From d8a3dbd9d78239b44dc444ce804cc9805741724d Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Sun, 29 Dec 2019 21:18:07 -0800 Subject: [PATCH] fixy --- package-lock.json | 53 +++++++++++++++++++++++++++++ package.json | 2 ++ src/init.ts | 15 ++++---- test/fixtures/kitchen/src/server.ts | 2 +- test/kitchen.ts | 28 +++++++-------- 5 files changed, 74 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0b6b3185..b62be075 100644 --- a/package-lock.json +++ b/package-lock.json @@ -135,6 +135,12 @@ "defer-to-connect": "^1.0.1" } }, + "@types/chai": { + "version": "4.2.7", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.7.tgz", + "integrity": "sha512-luq8meHGYwvky0O7u0eQZdA7B4Wd9owUCqvbw2m3XCrCU8mplYOujMBbvyS547AxJkC+pGnd0Cm15eNxEUNU8g==", + "dev": true + }, "@types/color-name": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", @@ -509,6 +515,12 @@ "is-regexp": "^1.0.0" } }, + "assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "dev": true + }, "astral-regex": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", @@ -697,6 +709,20 @@ "quick-lru": "^1.0.0" } }, + "chai": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", + "integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==", + "dev": true, + "requires": { + "assertion-error": "^1.1.0", + "check-error": "^1.0.2", + "deep-eql": "^3.0.1", + "get-func-name": "^2.0.0", + "pathval": "^1.1.0", + "type-detect": "^4.0.5" + } + }, "chalk": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", @@ -711,6 +737,12 @@ "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==" }, + "check-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", + "dev": true + }, "ci-info": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz", @@ -913,6 +945,15 @@ "mimic-response": "^1.0.0" } }, + "deep-eql": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", + "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", + "dev": true, + "requires": { + "type-detect": "^4.0.0" + } + }, "deep-extend": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", @@ -1471,6 +1512,12 @@ "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true }, + "get-func-name": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", + "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", + "dev": true + }, "get-stdin": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", @@ -2786,6 +2833,12 @@ "pify": "^3.0.0" } }, + "pathval": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", + "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", + "dev": true + }, "pify": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", diff --git a/package.json b/package.json index d5f2ae03..0f5c860a 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ }, "devDependencies": { "@npm/types": "^1.0.1", + "@types/chai": "^4.2.7", "@types/cross-spawn": "^6.0.0", "@types/eslint": "^6.1.3", "@types/fs-extra": "^8.0.0", @@ -72,6 +73,7 @@ "@types/write-file-atomic": "^2.1.2", "assert-rejects": "^1.0.0", "c8": "^7.0.0", + "chai": "^4.2.0", "codecov": "^3.0.1", "cross-spawn": "^7.0.0", "fs-extra": "^8.0.0", diff --git a/src/init.ts b/src/init.ts index 8445f416..657c9989 100644 --- a/src/init.ts +++ b/src/init.ts @@ -178,11 +178,8 @@ async function writePackageJson( options.logger.dir(preview); } -export const TSLINT_CONFIG = { - extends: 'gts/tslint.json', - linterOptions: { - exclude: ['**/*.json'], - }, +export const ESLINT_CONFIG = { + extends: './node_modules/gts/build/src/index.js', }; async function generateConfigFile( @@ -223,11 +220,11 @@ async function generateConfigFile( } } -async function generateTsLintConfig(options: Options): Promise { +async function generateESLintConfig(options: Options): Promise { return generateConfigFile( options, - './tslint.json', - formatJson(TSLINT_CONFIG) + './.eslintrc.json', + formatJson(ESLINT_CONFIG) ); } @@ -312,7 +309,7 @@ export async function init(options: Options): Promise { options.logger.log('No edits needed in package.json.'); } await generateTsConfig(options); - await generateTsLintConfig(options); + await generateESLintConfig(options); await generatePrettierConfig(options); await installDefaultTemplate(options); diff --git a/test/fixtures/kitchen/src/server.ts b/test/fixtures/kitchen/src/server.ts index 52fb2ed6..f463fff9 100644 --- a/test/fixtures/kitchen/src/server.ts +++ b/test/fixtures/kitchen/src/server.ts @@ -1 +1 @@ -const isThisTypeScript = true; +const isThisTypeScript = true diff --git a/test/kitchen.ts b/test/kitchen.ts index 7cea0e70..10474e82 100644 --- a/test/kitchen.ts +++ b/test/kitchen.ts @@ -2,11 +2,12 @@ import chalk = require('chalk'); import * as cp from 'child_process'; import * as fs from 'fs-extra'; import * as tmp from 'tmp'; -import * as assert from 'assert'; +import { assert } from 'chai'; import * as path from 'path'; import { describe, it, before, after } from 'mocha'; import spawn = require('cross-spawn'); +import execa = require('execa'); // eslint-disable-next-line @typescript-eslint/no-var-requires const pkg = require('../../package.json'); const keep = !!process.env.GTS_KEEP_TEMPDIRS; @@ -17,8 +18,6 @@ const execOpts = { encoding: 'utf8', }; -console.log(`${chalk.blue(`${__filename} staging area: ${stagingPath}`)}`); - describe('🚰 kitchen sink', () => { const fixturesPath = path.join('test', 'fixtures'); const gtsPath = path.join('node_modules', '.bin', 'gts'); @@ -26,6 +25,7 @@ describe('🚰 kitchen sink', () => { // Create a staging directory with temp fixtures used to test on a fresh application. before(() => { + console.log(`${chalk.blue(`${__filename} staging area: ${stagingPath}`)}`); cp.execSync('npm pack'); const tarball = `${pkg.name}-${pkg.version}.tgz`; fs.renameSync(tarball, 'gts.tgz'); @@ -59,7 +59,7 @@ describe('🚰 kitchen sink', () => { // Ensure config files got generated. fs.accessSync(path.join(kitchenPath, 'tsconfig.json')); - fs.accessSync(path.join(kitchenPath, 'tslint.json')); + fs.accessSync(path.join(kitchenPath, '.eslintrc.json')); fs.accessSync(path.join(kitchenPath, 'prettier.config.js')); // Compilation shouldn't have happened. Hence no `build` directory. @@ -119,23 +119,19 @@ describe('🚰 kitchen sink', () => { ); assert.ok( fs - .readFileSync(path.join(kitchenPath, 'tslint.json'), 'utf8') + .readFileSync(path.join(kitchenPath, '.eslintrc.json'), 'utf8') .endsWith('\n') ); }); - it('should check before fix', () => { - assert.throws( - () => { - cp.execSync('npm run check', execOpts); - }, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (err: any) => { - assert.strictEqual(err.status, 1); - assert.ok(err.stdout.includes('prettier reported errors')); - return true; - } + it('should check before fix', async () => { + const res = await execa( + 'npm', + ['run', 'check'], + Object.assign({}, { reject: false }, execOpts) ); + assert.strictEqual(res.exitCode, 1); + assert.include(res.stdout, 'assigned a value but'); }); it('should fix', () => {