From c7b883f8323b906fd3e649d4b9390fb7dbb02e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Fri, 31 Dec 2021 12:25:39 +0000 Subject: [PATCH] feat: wip --- README.md | 1 + dist/index.js | 130 ++++++++++-------- package.json | 2 +- src/peer-dependencies.ts | 2 +- src/run-tester.ts | 71 ++++++---- .../eslint-remote-tester.typescript.config.ts | 12 ++ test/run-tester.test.ts | 114 +++++++++++++-- yarn.lock | 19 ++- 8 files changed, 245 insertions(+), 106 deletions(-) create mode 100644 test/eslint-remote-tester.typescript.config.ts diff --git a/README.md b/README.md index cfe6b12..0c854e6 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Check out the use case description from eslint-remote-tester's documentation: [P | :-----------------------------: | :------------------: | | `v1` | `1.0.1` or above | | `v2` | `1.0.1` or above | +| `v3` | `2.1.0` or above | ## Configuration: diff --git a/dist/index.js b/dist/index.js index 50b8056..7f6bfab 100644 --- a/dist/index.js +++ b/dist/index.js @@ -152,11 +152,11 @@ var require_core = __commonJS((exports2) => { "use strict"; var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { - return value instanceof P ? value : new P(function(resolve) { - resolve(value); + return value instanceof P ? value : new P(function(resolve2) { + resolve2(value); }); } - return new (P || (P = Promise))(function(resolve, reject) { + return new (P || (P = Promise))(function(resolve2, reject) { function fulfilled(value) { try { step(generator.next(value)); @@ -172,7 +172,7 @@ var require_core = __commonJS((exports2) => { } } function step(result) { - result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); @@ -707,13 +707,13 @@ var require_http_client = __commonJS((exports2) => { this.message = message; } readBody() { - return new Promise(async (resolve, reject) => { + return new Promise(async (resolve2, reject) => { let output = Buffer.alloc(0); this.message.on("data", (chunk) => { output = Buffer.concat([output, chunk]); }); this.message.on("end", () => { - resolve(output.toString()); + resolve2(output.toString()); }); }); } @@ -877,12 +877,12 @@ var require_http_client = __commonJS((exports2) => { this._disposed = true; } requestRaw(info3, data) { - return new Promise((resolve, reject) => { + return new Promise((resolve2, reject) => { let callbackForResult = function(err, res) { if (err) { reject(err); } - resolve(res); + resolve2(res); }; this.requestRawWithCallback(info3, data, callbackForResult); }); @@ -1028,7 +1028,7 @@ var require_http_client = __commonJS((exports2) => { _performExponentialBackoff(retryNumber) { retryNumber = Math.min(ExponentialBackoffCeiling, retryNumber); const ms = ExponentialBackoffTimeSlice * Math.pow(2, retryNumber); - return new Promise((resolve) => setTimeout(() => resolve(), ms)); + return new Promise((resolve2) => setTimeout(() => resolve2(), ms)); } static dateTimeDeserializer(key, value) { if (typeof value === "string") { @@ -1040,7 +1040,7 @@ var require_http_client = __commonJS((exports2) => { return value; } async _processResponse(res, options) { - return new Promise(async (resolve, reject) => { + return new Promise(async (resolve2, reject) => { const statusCode = res.message.statusCode; const response = { statusCode, @@ -1048,7 +1048,7 @@ var require_http_client = __commonJS((exports2) => { headers: {} }; if (statusCode == HttpCodes.NotFound) { - resolve(response); + resolve2(response); } let obj; let contents; @@ -1078,7 +1078,7 @@ var require_http_client = __commonJS((exports2) => { err.result = response.result; reject(err); } else { - resolve(response); + resolve2(response); } }); } @@ -1904,7 +1904,7 @@ var require_lib = __commonJS((exports2) => { let accum = []; let accumBytes = 0; let abort = false; - return new Body.Promise(function(resolve, reject) { + return new Body.Promise(function(resolve2, reject) { let resTimeout; if (_this4.timeout) { resTimeout = setTimeout(function() { @@ -1938,7 +1938,7 @@ var require_lib = __commonJS((exports2) => { } clearTimeout(resTimeout); try { - resolve(Buffer.concat(accum, accumBytes)); + resolve2(Buffer.concat(accum, accumBytes)); } catch (err) { reject(new FetchError(`Could not create Buffer from response body for ${_this4.url}: ${err.message}`, "system", err)); } @@ -2520,7 +2520,7 @@ var require_lib = __commonJS((exports2) => { throw new Error("native promise missing, set fetch.Promise to your favorite alternative"); } Body.Promise = fetch.Promise; - return new fetch.Promise(function(resolve, reject) { + return new fetch.Promise(function(resolve2, reject) { const request = new Request(url, opts); const options = getNodeRequestOptions(request); const send = (options.protocol === "https:" ? import_https.default : import_http.default).request; @@ -2618,7 +2618,7 @@ var require_lib = __commonJS((exports2) => { requestOpts.body = void 0; requestOpts.headers.delete("content-length"); } - resolve(fetch(new Request(locationURL, requestOpts))); + resolve2(fetch(new Request(locationURL, requestOpts))); finalize(); return; } @@ -2640,7 +2640,7 @@ var require_lib = __commonJS((exports2) => { const codings = headers.get("Content-Encoding"); if (!request.compress || request.method === "HEAD" || codings === null || res.statusCode === 204 || res.statusCode === 304) { response = new Response(body, response_options); - resolve(response); + resolve2(response); return; } const zlibOptions = { @@ -2650,7 +2650,7 @@ var require_lib = __commonJS((exports2) => { if (codings == "gzip" || codings == "x-gzip") { body = body.pipe(import_zlib.default.createGunzip(zlibOptions)); response = new Response(body, response_options); - resolve(response); + resolve2(response); return; } if (codings == "deflate" || codings == "x-deflate") { @@ -2662,18 +2662,18 @@ var require_lib = __commonJS((exports2) => { body = body.pipe(import_zlib.default.createInflateRaw()); } response = new Response(body, response_options); - resolve(response); + resolve2(response); }); return; } if (codings == "br" && typeof import_zlib.default.createBrotliDecompress === "function") { body = body.pipe(import_zlib.default.createBrotliDecompress()); response = new Response(body, response_options); - resolve(response); + resolve2(response); return; } response = new Response(body, response_options); - resolve(response); + resolve2(response); }); writeToStream(req, request); }); @@ -4499,11 +4499,11 @@ var require_io_util = __commonJS((exports2) => { "use strict"; var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { - return value instanceof P ? value : new P(function(resolve) { - resolve(value); + return value instanceof P ? value : new P(function(resolve2) { + resolve2(value); }); } - return new (P || (P = Promise))(function(resolve, reject) { + return new (P || (P = Promise))(function(resolve2, reject) { function fulfilled(value) { try { step(generator.next(value)); @@ -4519,7 +4519,7 @@ var require_io_util = __commonJS((exports2) => { } } function step(result) { - result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); @@ -4671,11 +4671,11 @@ var require_io = __commonJS((exports2) => { "use strict"; var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { - return value instanceof P ? value : new P(function(resolve) { - resolve(value); + return value instanceof P ? value : new P(function(resolve2) { + resolve2(value); }); } - return new (P || (P = Promise))(function(resolve, reject) { + return new (P || (P = Promise))(function(resolve2, reject) { function fulfilled(value) { try { step(generator.next(value)); @@ -4691,7 +4691,7 @@ var require_io = __commonJS((exports2) => { } } function step(result) { - result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); @@ -4899,11 +4899,11 @@ var require_toolrunner = __commonJS((exports2) => { "use strict"; var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { - return value instanceof P ? value : new P(function(resolve) { - resolve(value); + return value instanceof P ? value : new P(function(resolve2) { + resolve2(value); }); } - return new (P || (P = Promise))(function(resolve, reject) { + return new (P || (P = Promise))(function(resolve2, reject) { function fulfilled(value) { try { step(generator.next(value)); @@ -4919,7 +4919,7 @@ var require_toolrunner = __commonJS((exports2) => { } } function step(result) { - result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); @@ -5147,7 +5147,7 @@ var require_toolrunner = __commonJS((exports2) => { this.toolPath = path4.resolve(process.cwd(), this.options.cwd || process.cwd(), this.toolPath); } this.toolPath = yield io.which(this.toolPath, true); - return new Promise((resolve, reject) => { + return new Promise((resolve2, reject) => { this._debug(`exec tool: ${this.toolPath}`); this._debug("arguments:"); for (const arg of this.args) { @@ -5227,7 +5227,7 @@ var require_toolrunner = __commonJS((exports2) => { if (error2) { reject(error2); } else { - resolve(exitCode); + resolve2(exitCode); } }); if (this.options.input) { @@ -5355,11 +5355,11 @@ var require_exec = __commonJS((exports2) => { "use strict"; var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { - return value instanceof P ? value : new P(function(resolve) { - resolve(value); + return value instanceof P ? value : new P(function(resolve2) { + resolve2(value); }); } - return new (P || (P = Promise))(function(resolve, reject) { + return new (P || (P = Promise))(function(resolve2, reject) { function fulfilled(value) { try { step(generator.next(value)); @@ -5375,7 +5375,7 @@ var require_exec = __commonJS((exports2) => { } } function step(result) { - result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + result.done ? resolve2(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); @@ -5825,7 +5825,7 @@ var GithubClient = class { } }; async function sleep(timeMs) { - await new Promise((resolve) => setTimeout(resolve, timeMs)); + await new Promise((resolve2) => setTimeout(resolve2, timeMs)); } var github_client_default = new GithubClient(); @@ -5840,7 +5840,7 @@ var import_compare = __toModule(require_compare()); var core2 = __toModule(require_core()); var DEPENDENCY_TO_INFO = { "eslint-remote-tester": { - minVersion: "1.0.1", + minVersion: "2.1.0", exportPath: "eslint-remote-tester/dist/exports-for-compare-action", packageJsonPath: "eslint-remote-tester/package.json", bin: "eslint-remote-tester" @@ -5868,21 +5868,13 @@ function requirePeerDependency(dependency) { } // src/run-tester.ts -var INTERNAL_CONFIG = "./eslint-remote-tester-runner-internal.config.js"; +var INTERNAL_CONFIG = "./eslint-remote-tester-runner-internal.config"; var RESULTS_TMP = "/tmp/results.json"; var DEFAULT_CONFIG = { cache: false, CI: true }; -var CONFIGURATION_TEMPLATE = (pathToUsersConfiguration) => `// Generated by eslint-remote-tester-run-action -const fs = require('fs'); - -// Load user's eslint-remote-tester.config.js -const usersConfig = require('${pathToUsersConfiguration}'); - -module.exports = { - ...usersConfig, - +var CONFIGURATION_TEMPLATE_BASE = ` // Values from eslint-remote-tester-run-action's default configuration ...${JSON.stringify(DEFAULT_CONFIG, null, 4)}, @@ -5894,7 +5886,31 @@ module.exports = { await usersConfig.onComplete(results, comparisonResults, repositoryCount); } } +`; +var CONFIGURATION_TEMPLATE_JS = (pathToUsersConfiguration) => `// Generated by eslint-remote-tester-run-action +const fs = require('fs'); + +// Load user's eslint-remote-tester.config.js +const usersConfig = require('${pathToUsersConfiguration}'); + +module.exports = { + ...usersConfig, + ${CONFIGURATION_TEMPLATE_BASE} +}; +`; +var CONFIGURATION_TEMPLATE_TS = (pathToUsersConfiguration) => `// Generated by eslint-remote-tester-run-action +import fs from 'fs'; +import type { Config } from 'eslint-remote-tester'; + +// Load user's eslint-remote-tester.config.ts +import usersConfig from '${pathToUsersConfiguration.replace(/\.ts$/, "")}'; + +const config: Config = { + ...usersConfig, + ${CONFIGURATION_TEMPLATE_BASE} }; + +export default config; `; async function runTester(configLocation) { const usersConfigLocation = import_path2.default.resolve(configLocation); @@ -5904,16 +5920,20 @@ async function runTester(configLocation) { if (!import_fs.default.existsSync(usersConfigLocation)) { throw new Error(`Unable to find eslint-remote-tester config with path ${usersConfigLocation}`); } - import_fs.default.writeFileSync(INTERNAL_CONFIG, CONFIGURATION_TEMPLATE(usersConfigLocation)); + const extension = usersConfigLocation.split(".").pop(); + const configTemplate = extension === "ts" ? CONFIGURATION_TEMPLATE_TS : CONFIGURATION_TEMPLATE_JS; + const createdConfig = `${INTERNAL_CONFIG}.${extension}`; + import_fs.default.writeFileSync(createdConfig, configTemplate(usersConfigLocation)); + const {validateConfig} = requirePeerDependency("eslint-remote-tester"); let config; try { - config = require(import_path2.default.resolve(INTERNAL_CONFIG)); + const {loadConfig} = require(import_path2.resolve("./node_modules/eslint-remote-tester/dist/config/load")); + config = loadConfig(import_path2.default.resolve(createdConfig)); } catch (e) { throw e; } - const {validateConfig} = requirePeerDependency("eslint-remote-tester"); await validateConfig(config, false); - await import_exec.exec(`${ESLINT_REMOTE_TESTER_BIN} --config ${INTERNAL_CONFIG}`, [], { + await import_exec.exec(`${ESLINT_REMOTE_TESTER_BIN} --config ${createdConfig}`, [], { ignoreReturnCode: true, env: {...process.env, NODE_OPTIONS: "--max_old_space_size=5120"} }); diff --git a/package.json b/package.json index 8dec528..461eab9 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "@actions/core": "^1.2.6", "@actions/exec": "^1.0.4", "@actions/github": "^4.0.0", - "eslint-remote-tester": "^1.2.0", + "eslint-remote-tester": "^2.1.0", "semver": "^7.3.4" }, "devDependencies": { diff --git a/src/peer-dependencies.ts b/src/peer-dependencies.ts index 20b4fc3..1aedabe 100644 --- a/src/peer-dependencies.ts +++ b/src/peer-dependencies.ts @@ -21,7 +21,7 @@ interface DependencyInfo { // Changes to minVersion's require major release const DEPENDENCY_TO_INFO: Record = { 'eslint-remote-tester': { - minVersion: '1.0.1', + minVersion: '2.1.0', exportPath: 'eslint-remote-tester/dist/exports-for-compare-action', packageJsonPath: 'eslint-remote-tester/package.json', bin: 'eslint-remote-tester', diff --git a/src/run-tester.ts b/src/run-tester.ts index 974bfe8..3a6e419 100644 --- a/src/run-tester.ts +++ b/src/run-tester.ts @@ -1,14 +1,14 @@ import fs from 'fs'; -import path from 'path'; +import path, { resolve } from 'path'; import { exec } from '@actions/exec'; -import { Config } from 'eslint-remote-tester/dist/exports-for-compare-action'; +import type { Config } from 'eslint-remote-tester'; import { - requirePeerDependency, ESLINT_REMOTE_TESTER_BIN, + requirePeerDependency, } from './peer-dependencies'; -const INTERNAL_CONFIG = './eslint-remote-tester-runner-internal.config.js'; +const INTERNAL_CONFIG = './eslint-remote-tester-runner-internal.config'; export const RESULTS_TMP = '/tmp/results.json'; /** @@ -19,19 +19,7 @@ const DEFAULT_CONFIG: Partial = { CI: true, }; -// prettier-ignore -const CONFIGURATION_TEMPLATE = ( - pathToUsersConfiguration: string -) => - `// Generated by eslint-remote-tester-run-action -const fs = require('fs'); - -// Load user's eslint-remote-tester.config.js -const usersConfig = require('${pathToUsersConfiguration}'); - -module.exports = { - ...usersConfig, - +const CONFIGURATION_TEMPLATE_BASE = ` // Values from eslint-remote-tester-run-action's default configuration ...${JSON.stringify(DEFAULT_CONFIG, null, 4)}, @@ -43,9 +31,37 @@ module.exports = { await usersConfig.onComplete(results, comparisonResults, repositoryCount); } } +`; + +const CONFIGURATION_TEMPLATE_JS = (pathToUsersConfiguration: string) => + `// Generated by eslint-remote-tester-run-action +const fs = require('fs'); + +// Load user's eslint-remote-tester.config.js +const usersConfig = require('${pathToUsersConfiguration}'); + +module.exports = { + ...usersConfig, + ${CONFIGURATION_TEMPLATE_BASE} }; `; +const CONFIGURATION_TEMPLATE_TS = (pathToUsersConfiguration: string) => + `// Generated by eslint-remote-tester-run-action +import fs from 'fs'; +import type { Config } from 'eslint-remote-tester'; + +// Load user's eslint-remote-tester.config.ts +import usersConfig from '${pathToUsersConfiguration.replace(/\.ts$/, '')}'; + +const config: Config = { + ...usersConfig, + ${CONFIGURATION_TEMPLATE_BASE} +}; + +export default config; +`; + /** * Run `eslint-remote-tester` and save results to temporary location */ @@ -65,27 +81,34 @@ export default async function runTester(configLocation: string): Promise { ); } + const extension = usersConfigLocation.split('.').pop(); + const configTemplate = + extension === 'ts' + ? CONFIGURATION_TEMPLATE_TS + : CONFIGURATION_TEMPLATE_JS; + const createdConfig = `${INTERNAL_CONFIG}.${extension}`; + // Write eslint-remote-tester configuration file - fs.writeFileSync( - INTERNAL_CONFIG, - CONFIGURATION_TEMPLATE(usersConfigLocation) - ); + fs.writeFileSync(createdConfig, configTemplate(usersConfigLocation)); + const { validateConfig } = requirePeerDependency('eslint-remote-tester'); let config: Config; // Useless try-catch required by esbuild // eslint-disable-next-line no-useless-catch try { - config = require(path.resolve(INTERNAL_CONFIG)); + const { loadConfig } = require(resolve( + './node_modules/eslint-remote-tester/dist/config/load' + )); + config = loadConfig(path.resolve(createdConfig)); } catch (e) { throw e; } // Validate configuration before run - const { validateConfig } = requirePeerDependency('eslint-remote-tester'); await validateConfig(config, false); - await exec(`${ESLINT_REMOTE_TESTER_BIN} --config ${INTERNAL_CONFIG}`, [], { + await exec(`${ESLINT_REMOTE_TESTER_BIN} --config ${createdConfig}`, [], { ignoreReturnCode: true, env: { ...process.env, NODE_OPTIONS: '--max_old_space_size=5120' }, }); diff --git a/test/eslint-remote-tester.typescript.config.ts b/test/eslint-remote-tester.typescript.config.ts new file mode 100644 index 0000000..9e0200e --- /dev/null +++ b/test/eslint-remote-tester.typescript.config.ts @@ -0,0 +1,12 @@ +import type { Config } from 'eslint-remote-tester'; + +const config: Config = { + repositories: ['AriPerkkio/eslint-remote-tester-integration-test-target'], + extensions: ['.ts'], + eslintrc: { + root: true, + extends: ['eslint:recommended'], + }, +}; + +export default config; diff --git a/test/run-tester.test.ts b/test/run-tester.test.ts index 1b011ea..7d8bf5e 100644 --- a/test/run-tester.test.ts +++ b/test/run-tester.test.ts @@ -7,19 +7,20 @@ import { ESLINT_REMOTE_TESTER_BIN } from '../src/peer-dependencies'; import { sanitizeStackTrace } from './utils'; import { Config } from 'eslint-remote-tester/dist/exports-for-compare-action'; -const EXPECTED_RUN_CONFIG = './eslint-remote-tester-runner-internal.config.js'; -const CONFIG = './test/eslint-remote-tester.config.js'; +const EXPECTED_RUN_CONFIG = './eslint-remote-tester-runner-internal.config'; +const CONFIG_JS = './test/eslint-remote-tester.config.js'; +const CONFIG_TS = './test/eslint-remote-tester.typescript.config.ts'; const INVALID_CONFIG = './test/eslint-remote-tester.invalid.config.js'; const CONFIG_WITH_ON_COMPLETE = './test/eslint-remote-tester.config.onComplete.js'; jest.mock('@actions/exec', () => ({ exec: jest.fn() })); -function readRunConfig() { +function readRunConfig(extension: 'js' | 'ts') { let content: Config; jest.isolateModules(() => { - content = require(resolve(EXPECTED_RUN_CONFIG)); + content = require(resolve(`${EXPECTED_RUN_CONFIG}.${extension}`)); }); return content!; @@ -28,20 +29,24 @@ function readRunConfig() { function cleanup() { jest.resetModules(); - if (fs.existsSync(EXPECTED_RUN_CONFIG)) { - fs.unlinkSync(EXPECTED_RUN_CONFIG); - } + ['js', 'ts'].forEach(extension => { + const name = `${EXPECTED_RUN_CONFIG}.${extension}`; + + if (fs.existsSync(name)) { + fs.unlinkSync(name); + } + }); } describe('run-tester', () => { beforeEach(cleanup); afterEach(cleanup); - test('runs eslint-remote-tester with provided configuration', async () => { - await runTester(CONFIG); + test('runs eslint-remote-tester with provided Javascript configuration', async () => { + await runTester(CONFIG_JS); expect(exec).toHaveBeenCalledWith( - `${ESLINT_REMOTE_TESTER_BIN} --config ${EXPECTED_RUN_CONFIG}`, + `${ESLINT_REMOTE_TESTER_BIN} --config ${EXPECTED_RUN_CONFIG}.js`, [], { ignoreReturnCode: true, @@ -52,6 +57,85 @@ describe('run-tester', () => { ); }); + test('creates CommonJS module when using Javascript configuration file', async () => { + await runTester(CONFIG_JS); + + const configContents = fs.readFileSync( + `${EXPECTED_RUN_CONFIG}.js`, + 'utf8' + ); + + expect(sanitizeStackTrace(configContents)).toMatchInlineSnapshot(` + "// Generated by eslint-remote-tester-run-action + const fs = require('fs'); + + // Load user's eslint-remote-tester.config.js + const usersConfig = require('/test/eslint-remote-tester.config.js'); + + module.exports = { + ...usersConfig, + + // Values from eslint-remote-tester-run-action's default configuration + ...{ + \\"cache\\": false, + \\"CI\\": true + }, + + onComplete: async function onComplete(results, comparisonResults, repositoryCount) { + // Write results to cache + fs.writeFileSync('/tmp/results.json', JSON.stringify({ results, repositoryCount })); + + if(usersConfig.onComplete) { + await usersConfig.onComplete(results, comparisonResults, repositoryCount); + } + } + + }; + " + `); + }); + + test('creates ES module when using Typescript configuration file', async () => { + await runTester(CONFIG_TS); + + const configContents = fs.readFileSync( + `${EXPECTED_RUN_CONFIG}.ts`, + 'utf8' + ); + + expect(sanitizeStackTrace(configContents)).toMatchInlineSnapshot(` + "// Generated by eslint-remote-tester-run-action + import fs from 'fs'; + import type { Config } from 'eslint-remote-tester'; + + // Load user's eslint-remote-tester.config.ts + import usersConfig from '/test/eslint-remote-tester.typescript.config'; + + const config: Config = { + ...usersConfig, + + // Values from eslint-remote-tester-run-action's default configuration + ...{ + \\"cache\\": false, + \\"CI\\": true + }, + + onComplete: async function onComplete(results, comparisonResults, repositoryCount) { + // Write results to cache + fs.writeFileSync('/tmp/results.json', JSON.stringify({ results, repositoryCount })); + + if(usersConfig.onComplete) { + await usersConfig.onComplete(results, comparisonResults, repositoryCount); + } + } + + }; + + export default config; + " + `); + }); + test('throws if given configuration does not exist', () => { return expect(runTester('./non-existing-config')).rejects.toThrowError( /(?=.*Unable to find eslint-remote-tester config with path)(?=.*non-existing-config)/ @@ -61,7 +145,7 @@ describe('run-tester', () => { test('uses onComplete from users configuration', async () => { await runTester(CONFIG_WITH_ON_COMPLETE); - expect(sanitizeStackTrace(readRunConfig().onComplete!.toString())) + expect(sanitizeStackTrace(readRunConfig('js').onComplete!.toString())) .toMatchInlineSnapshot(` "async function onComplete(results, comparisonResults, repositoryCount) { // Write results to cache @@ -75,15 +159,15 @@ describe('run-tester', () => { }); test('cache is disabled by default', async () => { - await runTester(CONFIG); + await runTester(CONFIG_JS); - expect(readRunConfig().cache).toBe(false); + expect(readRunConfig('js').cache).toBe(false); }); test('CI is enabled by default', async () => { - await runTester(CONFIG); + await runTester(CONFIG_JS); - expect(readRunConfig().CI).toBe(true); + expect(readRunConfig('js').CI).toBe(true); }); test('configuration is validated', () => { diff --git a/yarn.lock b/yarn.lock index ead8617..3f1a6fc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1952,17 +1952,17 @@ eslint-plugin-prettier@^3.3.1: dependencies: prettier-linter-helpers "^1.0.0" -eslint-remote-tester@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/eslint-remote-tester/-/eslint-remote-tester-1.2.0.tgz#eea8cb72b60de530b0f10a2af0d54c13e0713f95" - integrity sha512-VwippmgzkMbcLG3qK6JekmN1K1LfKXHVLh++xz+8jBZddWxEI+XMcZk9fOVPTMuNmJOdHogMgp/sptPfaBZC3Q== +eslint-remote-tester@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/eslint-remote-tester/-/eslint-remote-tester-2.1.0.tgz#9b82f175c40c87b8e9bb6d2764e5c5e2999aa59e" + integrity sha512-dLTbS+xo0Byj1QPsaYtgAChCmCORoM9s6CXHPWO4RLUbScX/fIToAAxZxwUGBJFiI0jxuKKLLFtvgstXfOYkIQ== dependencies: "@babel/code-frame" "^7.12.13" JSONStream "^1.3.5" chalk "^4.1.0" ink "^3.0.8" object-hash "^2.1.1" - react "^16.14.0" + react ">=16.8.0" simple-git "^2.20.1" eslint-scope@^5.0.0, eslint-scope@^5.1.1: @@ -4485,14 +4485,13 @@ react-reconciler@^0.24.0: prop-types "^15.6.2" scheduler "^0.18.0" -react@^16.14.0: - version "16.14.0" - resolved "https://registry.yarnpkg.com/react/-/react-16.14.0.tgz#94d776ddd0aaa37da3eda8fc5b6b18a4c9a3114d" - integrity sha512-0X2CImDkJGApiAlcf0ODKIneSwBPhqJawOa5wCtKbu7ZECrmS26NvtSILynQ66cgkT/RJ4LidJOc3bUESwmU8g== +react@>=16.8.0: + version "17.0.2" + resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037" + integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA== dependencies: loose-envify "^1.1.0" object-assign "^4.1.1" - prop-types "^15.6.2" read-pkg-up@^4.0.0: version "4.0.0"