From 842f355ea5958c82ebada3e4097ce85202a6aaaf Mon Sep 17 00:00:00 2001 From: armano2 Date: Mon, 9 May 2022 03:31:19 +0200 Subject: [PATCH 1/3] test: correct execution of test and dev scripts on Windows machines --- packages/types/tools/copy-ast-spec.ts | 6 ++++-- .../tests/ast-alignment/fixtures-to-test.ts | 6 ++++-- packages/typescript-estree/tests/ast-fixtures.test.ts | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/types/tools/copy-ast-spec.ts b/packages/types/tools/copy-ast-spec.ts index 8b7848d9a71..7e0ffa8d8b4 100644 --- a/packages/types/tools/copy-ast-spec.ts +++ b/packages/types/tools/copy-ast-spec.ts @@ -60,14 +60,16 @@ async function copyFile( encoding: 'utf-8', }); - await execAsync('yarn', ['prettier', '--write', outpath], {}); + await execAsync('yarn', ['prettier', '--write', outpath], { + shell: true, + }); console.log('Copied', fileName); } async function main(): Promise { // ensure the package is built - await execAsync('yarn', ['build'], { cwd: AST_SPEC_PATH }); + await execAsync('yarn', ['build'], { cwd: AST_SPEC_PATH, shell: true }); await Promise.all([ copyFile('dist', 'ast-spec.ts', code => diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index 5c3900f5ba8..5f44161557c 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -92,7 +92,10 @@ class FixturesTester { return this.fixtures .map(fixture => glob - .sync(`${fixture.directory}/${fixture.pattern}`, {}) + .sync(fixture.pattern, { + cwd: fixture.directory, + absolute: true, + }) .map(filename => ({ filename, ignoreSourceType: fixture.ignoreSourceType, @@ -346,7 +349,6 @@ tester.addFixturePatternConfig('typescript/basics', { /** * Not yet supported in Babel * Directive field is not added to module and namespace - * @see https://github.com/babel/babel/issues/9228 */ 'directive-in-module', 'directive-in-namespace', diff --git a/packages/typescript-estree/tests/ast-fixtures.test.ts b/packages/typescript-estree/tests/ast-fixtures.test.ts index f3ffbabd809..afccea2b854 100644 --- a/packages/typescript-estree/tests/ast-fixtures.test.ts +++ b/packages/typescript-estree/tests/ast-fixtures.test.ts @@ -28,7 +28,7 @@ const FIXTURES_DIR = path.resolve( const SNAPSHOTS_DIR = path.resolve(__dirname, 'snapshots'); const fixtures = glob - .sync(`${FIXTURES_DIR}/**/*.src.{js,ts,jsx,tsx}`) + .sync(`**/*.src.{js,ts,jsx,tsx}`, { cwd: FIXTURES_DIR, absolute: true }) .map(absolute => { const relative = path.relative(FIXTURES_DIR, absolute); const { name, dir, ext } = path.parse(relative); From 4c7603d2ea23be20841af739bec4a9cf57ac3aa1 Mon Sep 17 00:00:00 2001 From: armano2 Date: Tue, 10 May 2022 08:59:27 +0200 Subject: [PATCH 2/3] test: enable shell process.spawn only for windows --- packages/types/tools/copy-ast-spec.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/types/tools/copy-ast-spec.ts b/packages/types/tools/copy-ast-spec.ts index 7e0ffa8d8b4..7e4eff420c9 100644 --- a/packages/types/tools/copy-ast-spec.ts +++ b/packages/types/tools/copy-ast-spec.ts @@ -15,6 +15,7 @@ async function execAsync( return new Promise((resolve, reject) => { const child = childProcess.spawn(command, args, { ...options, + shell: process.platform === 'win32', stdio: 'inherit', }); @@ -60,16 +61,14 @@ async function copyFile( encoding: 'utf-8', }); - await execAsync('yarn', ['prettier', '--write', outpath], { - shell: true, - }); + await execAsync('yarn', ['prettier', '--write', outpath], {}); console.log('Copied', fileName); } async function main(): Promise { // ensure the package is built - await execAsync('yarn', ['build'], { cwd: AST_SPEC_PATH, shell: true }); + await execAsync('yarn', ['build'], { cwd: AST_SPEC_PATH }); await Promise.all([ copyFile('dist', 'ast-spec.ts', code => From 41a45360fbd03ce1798cdc6d3955b8925ce0286e Mon Sep 17 00:00:00 2001 From: armano2 Date: Tue, 10 May 2022 09:00:33 +0200 Subject: [PATCH 3/3] test: allow to run ONLY in ast-fixtures for windows --- .../tests/ast-fixtures.test.ts | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/packages/typescript-estree/tests/ast-fixtures.test.ts b/packages/typescript-estree/tests/ast-fixtures.test.ts index afccea2b854..37a7e5cb71f 100644 --- a/packages/typescript-estree/tests/ast-fixtures.test.ts +++ b/packages/typescript-estree/tests/ast-fixtures.test.ts @@ -15,7 +15,7 @@ addSerializer(serializer); // prettier-ignore const ONLY = [].join(path.sep); -const FIXTURES_DIR = path.resolve( +const fixturesDir = path.resolve( __dirname, '..', '..', @@ -25,15 +25,15 @@ const FIXTURES_DIR = path.resolve( 'shared-fixtures', 'fixtures', ); -const SNAPSHOTS_DIR = path.resolve(__dirname, 'snapshots'); +const snapshotsDir = path.resolve(__dirname, 'snapshots'); const fixtures = glob - .sync(`**/*.src.{js,ts,jsx,tsx}`, { cwd: FIXTURES_DIR, absolute: true }) + .sync(`**/*.src.{js,ts,jsx,tsx}`, { cwd: fixturesDir, absolute: true }) .map(absolute => { - const relative = path.relative(FIXTURES_DIR, absolute); + const relative = path.relative(fixturesDir, absolute); const { name, dir, ext } = path.parse(relative); const segments = dir.split(path.sep); - const snapshotPath = path.join(SNAPSHOTS_DIR, dir); + const snapshotPath = path.join(snapshotsDir, dir); return { absolute, isJsx: isJSXFileType(ext), @@ -97,14 +97,16 @@ fixtures.forEach(f => nestDescribe(f)); if (ONLY === '') { // ensure that the snapshots are cleaned up, because jest-specific-snapshot won't do this check - const snapshots = glob.sync(`${SNAPSHOTS_DIR}/**/*.shot`).map(absolute => { - const relative = path.relative(SNAPSHOTS_DIR, absolute); - const { name, dir } = path.parse(relative); - return { - relative, - fixturePath: path.join(FIXTURES_DIR, dir, name), - }; - }); + const snapshots = glob + .sync(`**/*.shot`, { cwd: snapshotsDir, absolute: true }) + .map(absolute => { + const relative = path.relative(snapshotsDir, absolute); + const { name, dir } = path.parse(relative); + return { + relative, + fixturePath: path.join(fixturesDir, dir, name), + }; + }); describe('ast snapshots should have an associated test', () => { for (const snap of snapshots) {