From 17fadc8575e0082f6b84dbb0afcb03e4cd241038 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 5 Jul 2019 10:58:21 -0400 Subject: [PATCH 1/2] Added rudimentary end-to-end test infrastructure --- .eslintrc.json | 44 ++++++++++++++++ .gitignore | 1 + .prettierignore | 1 + .vscode/settings.json | 1 + README.md | 14 +++++- jest.config.js | 2 +- package.json | 6 ++- src/cli/runCli.ts | 14 ++++-- src/conversion/convertConfig.test.ts | 8 ++- src/conversion/convertConfig.ts | 6 ++- src/creation/writeConversionResults.test.ts | 14 +++++- src/creation/writeConversionResults.ts | 3 +- src/input/findConfiguration.ts | 2 +- src/input/findESLintConfiguration.test.ts | 19 +++++-- src/input/findESLintConfiguration.ts | 5 +- src/input/findOriginalConfigurations.test.ts | 1 + src/input/findOriginalConfigurations.ts | 2 +- src/types.ts | 5 ++ src/utils.ts | 2 + test/createTestArgs.js | 19 +++++++ test/createTestArgs.ts | 20 ++++++++ test/createTests.js | 47 +++++++++++++++++ test/createTests.ts | 46 +++++++++++++++++ test/expectFileContains.js | 18 +++++++ test/expectFileContains.ts | 25 ++++++++++ test/jest.config.js | 5 ++ test/runEndToEndTests.js | 11 ++++ test/runEndToEndTests.ts | 12 +++++ .../standalone tslint.json/.eslintrc.json | 50 +++++++++++++++++++ .../standalone tslint.json/expected.json | 50 +++++++++++++++++++ test/tests/standalone tslint.json/stderr.txt | 0 test/tests/standalone tslint.json/stdout.txt | 3 ++ test/tests/standalone tslint.json/tslint.json | 35 +++++++++++++ 33 files changed, 467 insertions(+), 24 deletions(-) create mode 100644 .eslintrc.json create mode 100644 .prettierignore create mode 100644 test/createTestArgs.js create mode 100644 test/createTestArgs.ts create mode 100644 test/createTests.js create mode 100644 test/createTests.ts create mode 100644 test/expectFileContains.js create mode 100644 test/expectFileContains.ts create mode 100644 test/jest.config.js create mode 100644 test/runEndToEndTests.js create mode 100644 test/runEndToEndTests.ts create mode 100644 test/tests/standalone tslint.json/.eslintrc.json create mode 100644 test/tests/standalone tslint.json/expected.json create mode 100644 test/tests/standalone tslint.json/stderr.txt create mode 100644 test/tests/standalone tslint.json/stdout.txt create mode 100644 test/tests/standalone tslint.json/tslint.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 000000000..d1ab19785 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,44 @@ +{ + "env": { + "es6": true, + "node": true + }, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "tsconfig.json", + "sourceType": "module" + }, + "plugins": ["@typescript-eslint", "@typescript-eslint/tslint"], + "rules": { + "@typescript-eslint/array-type": "error", + "@typescript-eslint/interface-name-prefix": "error", + "@typescript-eslint/member-ordering": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-param-reassign": "off", + "@typescript-eslint/no-parameter-properties": "off", + "@typescript-eslint/no-use-before-declare": "off", + "@typescript-eslint/promise-function-async": "off", + "@typescript-eslint/unbound-method": "off", + "arrow-body-style": "off", + "default-case": "off", + "linebreak-style": "off", + "no-bitwise": "off", + "no-empty": "off", + "no-empty-functions": "off", + "no-magic-numbers": "off", + "prefer-template": "off", + "@typescript-eslint/tslint/config": [ + "error", + { + "rules": { + "no-implicit-dependencies": [true, "dev"], + "strict-boolean-expressions": [ + true, + "allow-boolean-or-undefined", + "allow-number" + ] + } + } + ] + } +} diff --git a/.gitignore b/.gitignore index 14a0e6a33..390b1342f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ coverage/ node_modules/ src/**/*.js +test/tests/**/.eslintrc* diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..7470f987c --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +test/tests/**/* diff --git a/.vscode/settings.json b/.vscode/settings.json index 36eb0f1bc..d695c1f4c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,6 @@ "**/*.js.map": true, "**/*.js": { "when": "$(basename).ts" } }, + "prettier.ignorePath": ".prettierignore", "typescript.tsdk": "node_modules/typescript/lib" } diff --git a/README.md b/README.md index 18abc4c1d..a80f48c3b 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,23 @@ TSLint rules without ESLint equivalents will be wrapped with [eslint-plugin-tsli Each of these flags is optional. +#### `config` + +```shell +npx tslint-to-eslint-config --config ./project/eslintrc.js +``` + +_Default: `.eslintrc.json`_ + +Path to print the generated ESLint configuration file to. + #### `eslint` ```shell -npx tslint-to-eslint-config --eslint ./path/to/seslintrc.json +npx tslint-to-eslint-config --eslint ./path/to/eslintrc.json ``` -_Default: `.eslintrc.js`_ +_Default: `--config`'s value_ Path to an ESLint configuration file to read settings from. This isn't yet used for anything, but will eventually inform settings for the generated ESLint configuration file. diff --git a/jest.config.js b/jest.config.js index 1ab81f193..f329ba374 100644 --- a/jest.config.js +++ b/jest.config.js @@ -17,6 +17,6 @@ module.exports = { }, }, moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], - testRegex: "((\\.|/)test)\\.tsx?$", + testRegex: "src(.*)\\.test\\.tsx?$", testEnvironment: "node", }; diff --git a/package.json b/package.json index ff2c6ea2e..a325edac0 100644 --- a/package.json +++ b/package.json @@ -59,9 +59,11 @@ }, "scripts": { "eslint": "eslint \"./src/*.ts\" \"./src/**/*.ts\" --report-unused-disable-directives", - "prettier": "prettier \"./src/*.{js,json,ts,xml,yaml}\" \"./src/**/*.{js,json,ts,xml,yaml}\"", + "prettier": "prettier \"./src/*.{js,json,ts,xml,yaml}\" \"./src/**/*.{js,json,ts,xml,yaml}\" --ignore-path .prettierignore", "prettier:write": "npm run prettier -- --write", - "test": "jest", + "test:unit": "jest", + "test:end-to-end": "jest --config=test/jest.config.js", + "test:end-to-end:accept": "jest --config=test/jest.config.js --globals=\"{\\\"acceptTestChanges\\\": true }\"", "tsc": "tsc" }, "version": "0.1.7" diff --git a/src/cli/runCli.ts b/src/cli/runCli.ts index b457e931c..bb906171d 100644 --- a/src/cli/runCli.ts +++ b/src/cli/runCli.ts @@ -19,13 +19,17 @@ export const runCli = async ( ): Promise => { const command = new Command() .usage("[options] --language [language]") - .option("--eslint [eslint]", "eslint configuration file to convert") - .option("--package [package]", "package configuration file to convert") - .option("--tslint [tslint]", "tslint configuration file to convert") - .option("--typescript [typescript]", "typescript configuration file to convert") + .option("--config [config]", "eslint configuration file to output to") + .option("--eslint [eslint]", "eslint configuration file to convert using") + .option("--package [package]", "package configuration file to convert using") + .option("--tslint [tslint]", "tslint configuration file to convert using") + .option("--typescript [typescript]", "typescript configuration file to convert using") .option("-V --version", "output the package version"); - const parsedArgv = command.parse(rawArgv) as Partial; + const parsedArgv = { + config: "./eslintrc.json", + ...(command.parse(rawArgv) as Partial), + }; if ({}.hasOwnProperty.call(parsedArgv, "version")) { dependencies.logger.stdout.write(`${version}${EOL}`); diff --git a/src/conversion/convertConfig.test.ts b/src/conversion/convertConfig.test.ts index 8a8718f1a..fb21682db 100644 --- a/src/conversion/convertConfig.test.ts +++ b/src/conversion/convertConfig.test.ts @@ -28,7 +28,9 @@ describe("convertConfig", () => { const dependencies = createStubDependencies({ findOriginalConfigurations: async () => findError, }); - const settings = {}; + const settings = { + config: "./eslintrc.js", + }; // Act const result = await convertConfig(dependencies, settings); @@ -46,7 +48,9 @@ describe("convertConfig", () => { const dependencies = createStubDependencies({ findOriginalConfigurations: async () => findSuccess, }); - const settings = {}; + const settings = { + config: "./eslintrc.js", + }; // Act const result = await convertConfig(dependencies, settings); diff --git a/src/conversion/convertConfig.ts b/src/conversion/convertConfig.ts index fc4046a34..6701fd21d 100644 --- a/src/conversion/convertConfig.ts +++ b/src/conversion/convertConfig.ts @@ -25,7 +25,11 @@ export const convertConfig = async ( originalConfigurations.data.tslint.rules, ); - await dependencies.writeConversionResults(ruleConversionResults, originalConfigurations.data); + await dependencies.writeConversionResults( + settings.config, + ruleConversionResults, + originalConfigurations.data, + ); dependencies.reportConversionResults(ruleConversionResults); return { diff --git a/src/creation/writeConversionResults.test.ts b/src/creation/writeConversionResults.test.ts index 65258c19d..59f056f70 100644 --- a/src/creation/writeConversionResults.test.ts +++ b/src/creation/writeConversionResults.test.ts @@ -17,7 +17,12 @@ describe("writeConversionResults", () => { const fileSystem = { writeFile: jest.fn().mockReturnValue(Promise.resolve()) }; // Act - await writeConversionResults({ fileSystem }, conversionResults, originalConfigurations); + await writeConversionResults( + { fileSystem }, + ".eslintrc.json", + conversionResults, + originalConfigurations, + ); // Assert expect(fileSystem.writeFile).toHaveBeenLastCalledWith( @@ -58,7 +63,12 @@ describe("writeConversionResults", () => { const fileSystem = { writeFile: jest.fn().mockReturnValue(Promise.resolve()) }; // Act - await writeConversionResults({ fileSystem }, conversionResults, originalConfigurations); + await writeConversionResults( + { fileSystem }, + ".eslintrc.json", + conversionResults, + originalConfigurations, + ); // Assert expect(fileSystem.writeFile).toHaveBeenLastCalledWith( diff --git a/src/creation/writeConversionResults.ts b/src/creation/writeConversionResults.ts index f09fe8655..d1ae98c4c 100644 --- a/src/creation/writeConversionResults.ts +++ b/src/creation/writeConversionResults.ts @@ -10,6 +10,7 @@ export type WriteConversionResultsDependencies = { export const writeConversionResults = async ( dependencies: WriteConversionResultsDependencies, + outputPath: string, ruleConversionResults: RuleConversionResults, originalConfigurations: OriginalConfigurations, ) => { @@ -29,5 +30,5 @@ export const writeConversionResults = async ( rules: formatConvertedRules(ruleConversionResults, originalConfigurations.tslint), }; - await dependencies.fileSystem.writeFile(".eslintrc.json", JSON.stringify(output, undefined, 4)); + await dependencies.fileSystem.writeFile(outputPath, JSON.stringify(output, undefined, 4)); }; diff --git a/src/input/findConfiguration.ts b/src/input/findConfiguration.ts index 61260ddef..d91acb948 100644 --- a/src/input/findConfiguration.ts +++ b/src/input/findConfiguration.ts @@ -13,7 +13,7 @@ export const findConfiguration = async ( command: string, config: string, ): Promise | Error> => { - const fullCommand = `${command} ${config}`; + const fullCommand = `${command} "${config}"`; const stdout = await execAndCatch(exec, fullCommand); if (stdout instanceof Error) { diff --git a/src/input/findESLintConfiguration.test.ts b/src/input/findESLintConfiguration.test.ts index 0615c990d..79439e6f9 100644 --- a/src/input/findESLintConfiguration.test.ts +++ b/src/input/findESLintConfiguration.test.ts @@ -1,5 +1,12 @@ import { findESLintConfiguration } from "./findESLintConfiguration"; import { createStubExec, createStubThrowingExec } from "../adapters/exec.stubs"; +import { TSLintToESLintSettings } from "../types"; + +const createStubRawSettings = (overrides: Partial = {}) => ({ + config: "./eslintrc.json", + eslint: undefined, + ...overrides, +}); describe("findESLintConfiguration", () => { it("returns an error when one occurs", async () => { @@ -8,7 +15,7 @@ describe("findESLintConfiguration", () => { const dependencies = { exec: createStubThrowingExec({ stderr: message }) }; // Act - const result = await findESLintConfiguration(dependencies, undefined); + const result = await findESLintConfiguration(dependencies, createStubRawSettings()); // Assert expect(result).toEqual( @@ -23,7 +30,7 @@ describe("findESLintConfiguration", () => { const dependencies = { exec: createStubExec() }; // Act - await findESLintConfiguration(dependencies, undefined); + await findESLintConfiguration(dependencies, createStubRawSettings()); // Assert expect(dependencies.exec).toHaveBeenLastCalledWith("eslint --print-config ./eslintrc.js"); @@ -32,7 +39,9 @@ describe("findESLintConfiguration", () => { it("includes a configuration file in the ESLint command when one is provided", async () => { // Arrange const dependencies = { exec: createStubExec() }; - const config = "./custom/eslintrc.js"; + const config = createStubRawSettings({ + eslint: "./custom/eslintrc.js", + }); // Act await findESLintConfiguration(dependencies, config); @@ -46,7 +55,9 @@ describe("findESLintConfiguration", () => { it("applies ESLint defaults when none are provided", async () => { // Arrange const dependencies = { exec: createStubExec({ stdout: "{}" }) }; - const config = "./custom/eslintrc.js"; + const config = createStubRawSettings({ + eslint: "./custom/eslintrc.js", + }); // Act const result = await findESLintConfiguration(dependencies, config); diff --git a/src/input/findESLintConfiguration.ts b/src/input/findESLintConfiguration.ts index 179c82ccb..4171dda42 100644 --- a/src/input/findESLintConfiguration.ts +++ b/src/input/findESLintConfiguration.ts @@ -1,3 +1,4 @@ +import { TSLintToESLintSettings } from "../types"; import { findConfiguration, FindConfigurationDependencies } from "./findConfiguration"; export type ESLintConfiguration = { @@ -16,12 +17,12 @@ const defaultESLintConfiguration = { export const findESLintConfiguration = async ( dependencies: FindConfigurationDependencies, - config: string | undefined, + rawSettings: Pick, ): Promise => { const rawConfiguration = await findConfiguration( dependencies.exec, "eslint --print-config", - config || "./eslintrc.js", + rawSettings.eslint || rawSettings.config, ); return rawConfiguration instanceof Error diff --git a/src/input/findOriginalConfigurations.test.ts b/src/input/findOriginalConfigurations.test.ts index c2a36a815..83c62a764 100644 --- a/src/input/findOriginalConfigurations.test.ts +++ b/src/input/findOriginalConfigurations.test.ts @@ -5,6 +5,7 @@ import { import { ResultStatus } from "../types"; const createRawSettings = () => ({ + config: "./eslintrc.json", eslint: "", tslint: "", typescript: "", diff --git a/src/input/findOriginalConfigurations.ts b/src/input/findOriginalConfigurations.ts index a6559d975..a3b387b72 100644 --- a/src/input/findOriginalConfigurations.ts +++ b/src/input/findOriginalConfigurations.ts @@ -27,7 +27,7 @@ export const findOriginalConfigurations = async ( rawSettings: TSLintToESLintSettings, ): Promise> => { const [eslint, packages, tslint, typescript] = await Promise.all([ - dependencies.findESLintConfiguration(rawSettings.eslint), + dependencies.findESLintConfiguration(rawSettings), dependencies.findPackagesConfiguration(rawSettings.package), dependencies.findTSLintConfiguration(rawSettings.tslint), dependencies.findTypeScriptConfiguration(rawSettings.typescript), diff --git a/src/types.ts b/src/types.ts index cd347816e..474eb3f46 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,9 @@ export type TSLintToESLintSettings = { + /** + * Output ESLint configuration file path, such as `.eslintrc.js`. + */ + config: string; + /** * Original ESLint configuration file path, such as `.eslintrc.js`. */ diff --git a/src/utils.ts b/src/utils.ts index 0d87a3008..8deffdcd4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,3 +5,5 @@ export const isError = (item: Item | Error): item is Error => item instanc export type RemoveErrors = { [P in keyof Items]: Exclude; }; + +export type PromiseValue = T extends Promise ? R : never; diff --git a/test/createTestArgs.js b/test/createTestArgs.js new file mode 100644 index 000000000..ec61c401b --- /dev/null +++ b/test/createTestArgs.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs = require("fs"); +const path = require("path"); +const util_1 = require("util"); +const readdir = util_1.promisify(fs.readdir); +exports.createTestArgs = async cwd => { + const items = new Set(await readdir(cwd)); + const flags = [ + "--config", + path.join(cwd, ".eslintrc.json"), + "--tslint", + path.join(cwd, "tslint.json"), + ]; + if (items.has("tslint.json")) { + } + return flags.map(flag => `"${flag}"`).join(" "); +}; +//# sourceMappingURL=createTestArgs.js.map diff --git a/test/createTestArgs.ts b/test/createTestArgs.ts new file mode 100644 index 000000000..a4eac8f0a --- /dev/null +++ b/test/createTestArgs.ts @@ -0,0 +1,20 @@ +import * as fs from "fs"; +import * as path from "path"; +import { promisify } from "util"; + +const readdir = promisify(fs.readdir); + +export const createTestArgs = async (cwd: string) => { + const items = new Set(await readdir(cwd)); + const flags = [ + "--config", + path.join(cwd, ".eslintrc.json"), + "--tslint", + path.join(cwd, "tslint.json"), + ]; + + if (items.has("tslint.json")) { + } + + return flags.map(flag => `"${flag}"`).join(" "); +}; diff --git a/test/createTests.js b/test/createTests.js new file mode 100644 index 000000000..466e8e70f --- /dev/null +++ b/test/createTests.js @@ -0,0 +1,47 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const cp = require("child_process"); +const fs = require("fs"); +const path = require("path"); +const util_1 = require("util"); +const createTestArgs_1 = require("./createTestArgs"); +const expectFileContains_1 = require("./expectFileContains"); +const exec = util_1.promisify(cp.exec); +const readFile = util_1.promisify(fs.readFile); +exports.createTests = (testName, accept) => { + const cwd = path.join(__dirname, "tests", testName); + const cwdPath = fileName => path.join(cwd, fileName); + const readTestFile = async fileName => (await readFile(cwdPath(fileName))).toString(); + return () => { + let result; + beforeAll(async () => { + // Arrange + const args = await createTestArgs_1.createTestArgs(cwd); + // Act + result = await exec(`ts-node bin/tslint-to-eslint-config ${args}`); + }); + test("configuration output", async () => { + await expectFileContains_1.assertFileContents( + cwdPath("expected.json"), + await readTestFile(".eslintrc.json"), + accept, + ); + }); + // test("info log output", () => {}); + test("stderr", async () => { + await expectFileContains_1.assertFileContents( + cwdPath("stderr.txt"), + result.stderr, + accept, + ); + }); + test("stdout", async () => { + await expectFileContains_1.assertFileContents( + cwdPath("stdout.txt"), + result.stdout, + accept, + ); + }); + }; +}; +//# sourceMappingURL=createTests.js.map diff --git a/test/createTests.ts b/test/createTests.ts new file mode 100644 index 000000000..c7d2b7afc --- /dev/null +++ b/test/createTests.ts @@ -0,0 +1,46 @@ +import * as cp from "child_process"; +import * as fs from "fs"; +import * as path from "path"; +import { promisify } from "util"; + +import { createTestArgs } from "./createTestArgs"; +import { PromiseValue } from "../src/utils"; +import { assertFileContents } from "./expectFileContains"; + +const exec = promisify(cp.exec); +const readFile = promisify(fs.readFile); + +export const createTests = (testName: string, accept: boolean) => { + const cwd = path.join(__dirname, "tests", testName); + const cwdPath = (fileName: string) => path.join(cwd, fileName); + const readTestFile = async (fileName: string) => (await readFile(cwdPath(fileName))).toString(); + + return () => { + let result: PromiseValue>; + beforeAll(async () => { + // Arrange + const args = await createTestArgs(cwd); + + // Act + result = await exec(`ts-node bin/tslint-to-eslint-config ${args}`); + }); + + test("configuration output", async () => { + await assertFileContents( + cwdPath("expected.json"), + await readTestFile(".eslintrc.json"), + accept, + ); + }); + + // test("info log output", () => {}); + + test("stderr", async () => { + await assertFileContents(cwdPath("stderr.txt"), result.stderr, accept); + }); + + test("stdout", async () => { + await assertFileContents(cwdPath("stdout.txt"), result.stdout, accept); + }); + }; +}; diff --git a/test/expectFileContains.js b/test/expectFileContains.js new file mode 100644 index 000000000..122aedbb1 --- /dev/null +++ b/test/expectFileContains.js @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs = require("fs"); +const util_1 = require("util"); +const readFile = util_1.promisify(fs.readFile); +const writeFile = util_1.promisify(fs.writeFile); +const standardizeEndlines = text => text.replace(/\r/g, ""); +exports.assertFileContents = async (filePath, actual, accept) => { + await (accept ? acceptFileContents : expectFileContents)(filePath, actual.toString()); +}; +const acceptFileContents = async (filePath, actual) => { + await writeFile(filePath, actual); +}; +const expectFileContents = async (filePath, actual) => { + const expected = (await readFile(filePath)).toString(); + expect(standardizeEndlines(actual)).toEqual(standardizeEndlines(expected)); +}; +//# sourceMappingURL=expectFileContains.js.map diff --git a/test/expectFileContains.ts b/test/expectFileContains.ts new file mode 100644 index 000000000..1add7066d --- /dev/null +++ b/test/expectFileContains.ts @@ -0,0 +1,25 @@ +import * as fs from "fs"; +import { promisify } from "util"; + +const readFile = promisify(fs.readFile); +const writeFile = promisify(fs.writeFile); + +const standardizeEndlines = (text: string) => text.replace(/\r/g, ""); + +export const assertFileContents = async ( + filePath: string, + actual: string | Buffer, + accept: boolean, +) => { + await (accept ? acceptFileContents : expectFileContents)(filePath, actual.toString()); +}; + +const acceptFileContents = async (filePath: string, actual: string) => { + await writeFile(filePath, actual); +}; + +const expectFileContents = async (filePath: string, actual: string) => { + const expected = (await readFile(filePath)).toString(); + + expect(standardizeEndlines(actual)).toEqual(standardizeEndlines(expected)); +}; diff --git a/test/jest.config.js b/test/jest.config.js new file mode 100644 index 000000000..922024be5 --- /dev/null +++ b/test/jest.config.js @@ -0,0 +1,5 @@ +module.exports = { + moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], + testRegex: "test/runEndToEndTests.ts", + testEnvironment: "node", +}; diff --git a/test/runEndToEndTests.js b/test/runEndToEndTests.js new file mode 100644 index 000000000..5ab7e08a9 --- /dev/null +++ b/test/runEndToEndTests.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs = require("fs"); +const path = require("path"); +const createTests_1 = require("./createTests"); +const testNames = fs.readdirSync(path.join(__dirname, "tests")); +const accept = "acceptTestChanges" in globalThis; +for (const testName of testNames) { + describe(testName, createTests_1.createTests(testName, accept)); +} +//# sourceMappingURL=runEndToEndTests.js.map diff --git a/test/runEndToEndTests.ts b/test/runEndToEndTests.ts new file mode 100644 index 000000000..f6349ff48 --- /dev/null +++ b/test/runEndToEndTests.ts @@ -0,0 +1,12 @@ +import * as fs from "fs"; +import * as path from "path"; + +import { createTests } from "./createTests"; + +const testNames = fs.readdirSync(path.join(__dirname, "tests")); + +const accept = "acceptTestChanges" in globalThis; + +for (const testName of testNames) { + describe(testName, createTests(testName, accept)); +} diff --git a/test/tests/standalone tslint.json/.eslintrc.json b/test/tests/standalone tslint.json/.eslintrc.json new file mode 100644 index 000000000..495475d49 --- /dev/null +++ b/test/tests/standalone tslint.json/.eslintrc.json @@ -0,0 +1,50 @@ +{ + "env": { + "es6": true, + "node": true + }, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "tsconfig.json", + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint", + "@typescript-eslint/tslint" + ], + "rules": { + "@typescript-eslint/array-type": "error", + "@typescript-eslint/interface-name-prefix": "error", + "@typescript-eslint/member-ordering": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-param-reassign": "off", + "@typescript-eslint/no-parameter-properties": "off", + "@typescript-eslint/no-use-before-declare": "off", + "@typescript-eslint/promise-function-async": "off", + "@typescript-eslint/unbound-method": "off", + "arrow-body-style": "off", + "default-case": "off", + "linebreak-style": "off", + "no-bitwise": "off", + "no-empty": "off", + "no-empty-functions": "off", + "no-magic-numbers": "off", + "prefer-template": "off", + "@typescript-eslint/tslint/config": [ + "error", + { + "rules": { + "no-implicit-dependencies": [ + true, + "dev" + ], + "strict-boolean-expressions": [ + true, + "allow-boolean-or-undefined", + "allow-number" + ] + } + } + ] + } +} \ No newline at end of file diff --git a/test/tests/standalone tslint.json/expected.json b/test/tests/standalone tslint.json/expected.json new file mode 100644 index 000000000..495475d49 --- /dev/null +++ b/test/tests/standalone tslint.json/expected.json @@ -0,0 +1,50 @@ +{ + "env": { + "es6": true, + "node": true + }, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "tsconfig.json", + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint", + "@typescript-eslint/tslint" + ], + "rules": { + "@typescript-eslint/array-type": "error", + "@typescript-eslint/interface-name-prefix": "error", + "@typescript-eslint/member-ordering": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-param-reassign": "off", + "@typescript-eslint/no-parameter-properties": "off", + "@typescript-eslint/no-use-before-declare": "off", + "@typescript-eslint/promise-function-async": "off", + "@typescript-eslint/unbound-method": "off", + "arrow-body-style": "off", + "default-case": "off", + "linebreak-style": "off", + "no-bitwise": "off", + "no-empty": "off", + "no-empty-functions": "off", + "no-magic-numbers": "off", + "prefer-template": "off", + "@typescript-eslint/tslint/config": [ + "error", + { + "rules": { + "no-implicit-dependencies": [ + true, + "dev" + ], + "strict-boolean-expressions": [ + true, + "allow-boolean-or-undefined", + "allow-number" + ] + } + } + ] + } +} \ No newline at end of file diff --git a/test/tests/standalone tslint.json/stderr.txt b/test/tests/standalone tslint.json/stderr.txt new file mode 100644 index 000000000..e69de29bb diff --git a/test/tests/standalone tslint.json/stdout.txt b/test/tests/standalone tslint.json/stdout.txt new file mode 100644 index 000000000..fcf5848f3 --- /dev/null +++ b/test/tests/standalone tslint.json/stdout.txt @@ -0,0 +1,3 @@ +✨ 17 rules replaced with their ESLint equivalents. ✨ +️👀 2 rules do not yet have ESLint equivalents; defaulting to eslint-plugin-tslint. 👀 +✅ All is well! ✅ diff --git a/test/tests/standalone tslint.json/tslint.json b/test/tests/standalone tslint.json/tslint.json new file mode 100644 index 000000000..4a2aa47f4 --- /dev/null +++ b/test/tests/standalone tslint.json/tslint.json @@ -0,0 +1,35 @@ +{ + "rules": { + "array-type": [true, "array"], + "arrow-return-shorthand": false, + "completed-docs": false, + "comment-format": false, + "file-name-casing": false, + "linebreak-style": false, + "interface-name": [true, "never-prefix"], + "member-ordering": false, + "newline-before-return": false, + "no-any": false, + "no-bitwise": false, + "no-empty": false, + "no-magic-numbers": false, + "no-import-side-effect": false, + "no-implicit-dependencies": [true, "dev"], + "no-null-keyword": false, + "no-parameter-reassignment": false, + "no-parameter-properties": false, + "no-submodule-imports": false, + "no-unbound-method": false, + "no-unused-variable": false, + "no-use-before-declare": false, + "prefer-conditional-expression": false, + "prefer-method-signature": false, + "prefer-switch": false, + "prefer-template": false, + "promise-function-async": false, + "strict-boolean-expressions": [true, "allow-boolean-or-undefined", "allow-number"], + "switch-default": false, + "switch-final-break": false, + "typedef": false + } +} From 70675727ca628041ba8015bdfe81284871bcae99 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 5 Jul 2019 13:21:09 -0500 Subject: [PATCH 2/2] Removed added test .js files --- .gitignore | 1 + test/createTestArgs.js | 19 --------------- test/createTests.js | 47 -------------------------------------- test/expectFileContains.js | 18 --------------- test/runEndToEndTests.js | 11 --------- 5 files changed, 1 insertion(+), 95 deletions(-) delete mode 100644 test/createTestArgs.js delete mode 100644 test/createTests.js delete mode 100644 test/expectFileContains.js delete mode 100644 test/runEndToEndTests.js diff --git a/.gitignore b/.gitignore index 390b1342f..5635acd8f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ coverage/ node_modules/ src/**/*.js +test/*.js test/tests/**/.eslintrc* diff --git a/test/createTestArgs.js b/test/createTestArgs.js deleted file mode 100644 index ec61c401b..000000000 --- a/test/createTestArgs.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const fs = require("fs"); -const path = require("path"); -const util_1 = require("util"); -const readdir = util_1.promisify(fs.readdir); -exports.createTestArgs = async cwd => { - const items = new Set(await readdir(cwd)); - const flags = [ - "--config", - path.join(cwd, ".eslintrc.json"), - "--tslint", - path.join(cwd, "tslint.json"), - ]; - if (items.has("tslint.json")) { - } - return flags.map(flag => `"${flag}"`).join(" "); -}; -//# sourceMappingURL=createTestArgs.js.map diff --git a/test/createTests.js b/test/createTests.js deleted file mode 100644 index 466e8e70f..000000000 --- a/test/createTests.js +++ /dev/null @@ -1,47 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const cp = require("child_process"); -const fs = require("fs"); -const path = require("path"); -const util_1 = require("util"); -const createTestArgs_1 = require("./createTestArgs"); -const expectFileContains_1 = require("./expectFileContains"); -const exec = util_1.promisify(cp.exec); -const readFile = util_1.promisify(fs.readFile); -exports.createTests = (testName, accept) => { - const cwd = path.join(__dirname, "tests", testName); - const cwdPath = fileName => path.join(cwd, fileName); - const readTestFile = async fileName => (await readFile(cwdPath(fileName))).toString(); - return () => { - let result; - beforeAll(async () => { - // Arrange - const args = await createTestArgs_1.createTestArgs(cwd); - // Act - result = await exec(`ts-node bin/tslint-to-eslint-config ${args}`); - }); - test("configuration output", async () => { - await expectFileContains_1.assertFileContents( - cwdPath("expected.json"), - await readTestFile(".eslintrc.json"), - accept, - ); - }); - // test("info log output", () => {}); - test("stderr", async () => { - await expectFileContains_1.assertFileContents( - cwdPath("stderr.txt"), - result.stderr, - accept, - ); - }); - test("stdout", async () => { - await expectFileContains_1.assertFileContents( - cwdPath("stdout.txt"), - result.stdout, - accept, - ); - }); - }; -}; -//# sourceMappingURL=createTests.js.map diff --git a/test/expectFileContains.js b/test/expectFileContains.js deleted file mode 100644 index 122aedbb1..000000000 --- a/test/expectFileContains.js +++ /dev/null @@ -1,18 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const fs = require("fs"); -const util_1 = require("util"); -const readFile = util_1.promisify(fs.readFile); -const writeFile = util_1.promisify(fs.writeFile); -const standardizeEndlines = text => text.replace(/\r/g, ""); -exports.assertFileContents = async (filePath, actual, accept) => { - await (accept ? acceptFileContents : expectFileContents)(filePath, actual.toString()); -}; -const acceptFileContents = async (filePath, actual) => { - await writeFile(filePath, actual); -}; -const expectFileContents = async (filePath, actual) => { - const expected = (await readFile(filePath)).toString(); - expect(standardizeEndlines(actual)).toEqual(standardizeEndlines(expected)); -}; -//# sourceMappingURL=expectFileContains.js.map diff --git a/test/runEndToEndTests.js b/test/runEndToEndTests.js deleted file mode 100644 index 5ab7e08a9..000000000 --- a/test/runEndToEndTests.js +++ /dev/null @@ -1,11 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const fs = require("fs"); -const path = require("path"); -const createTests_1 = require("./createTests"); -const testNames = fs.readdirSync(path.join(__dirname, "tests")); -const accept = "acceptTestChanges" in globalThis; -for (const testName of testNames) { - describe(testName, createTests_1.createTests(testName, accept)); -} -//# sourceMappingURL=runEndToEndTests.js.map