Skip to content

Commit

Permalink
test: allow to execute tests on windows (#6488)
Browse files Browse the repository at this point in the history
* test: allow to execute tests on windows

* test: use path.posix instead of replace

* test: revert posix change
  • Loading branch information
armano2 committed Feb 18, 2023
1 parent 98dec37 commit ff6b190
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
14 changes: 11 additions & 3 deletions packages/ast-spec/tests/fixtures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,18 @@ const fixturesWithErrorDifferences = {
} as const;

const VALID_FIXTURES: readonly string[] = glob.sync(
`${SRC_DIR}/**/fixtures/*/fixture.{ts,tsx}`,
`**/fixtures/*/fixture.{ts,tsx}`,
{
cwd: SRC_DIR,
absolute: true,
},
);
const ERROR_FIXTURES: readonly string[] = glob.sync(
`${SRC_DIR}/**/fixtures/_error_/*/fixture.{ts,tsx}`,
`**/fixtures/_error_/*/fixture.{ts,tsx}`,
{
cwd: SRC_DIR,
absolute: true,
},
);

const FIXTURES: readonly Fixture[] = [...VALID_FIXTURES, ...ERROR_FIXTURES].map(
Expand All @@ -66,7 +74,7 @@ const FIXTURES: readonly Fixture[] = [...VALID_FIXTURES, ...ERROR_FIXTURES].map(
isError: absolute.includes('/_error_/'),
isJSX: ext.endsWith('x'),
name,
relative: path.relative(SRC_DIR, absolute),
relative: path.relative(SRC_DIR, absolute).replace(/\\/g, '/'),
segments,
snapshotFiles: {
success: {
Expand Down
26 changes: 18 additions & 8 deletions packages/typescript-estree/tests/lib/getProjectConfigFiles.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from 'path';

import { ExpiringCache } from '../../src/parseSettings/ExpiringCache';
import { getProjectConfigFiles } from '../../src/parseSettings/getProjectConfigFiles';

Expand Down Expand Up @@ -51,12 +53,16 @@ describe('getProjectConfigFiles', () => {
getProjectConfigFiles(parseSettings, true);
const actual = getProjectConfigFiles(parseSettings, true);

expect(actual).toEqual(['repos/repo/packages/package/tsconfig.json']);
expect(actual).toEqual([
path.normalize('repos/repo/packages/package/tsconfig.json'),
]);
expect(mockExistsSync).toHaveBeenCalledTimes(1);
});

it('returns a nearby parent tsconfig.json when it was previously cached by a different directory search', () => {
mockExistsSync.mockImplementation(input => input === 'a/tsconfig.json');
mockExistsSync.mockImplementation(
input => input === path.normalize('a/tsconfig.json'),
);

const tsconfigMatchCache = new ExpiringCache<string, string>(1);

Expand All @@ -81,12 +87,14 @@ describe('getProjectConfigFiles', () => {
true,
);

expect(actual).toEqual(['a/tsconfig.json']);
expect(actual).toEqual([path.normalize('a/tsconfig.json')]);
expect(mockExistsSync).toHaveBeenCalledTimes(4);
});

it('returns a distant parent tsconfig.json when it was previously cached by a different directory search', () => {
mockExistsSync.mockImplementation(input => input === 'a/tsconfig.json');
mockExistsSync.mockImplementation(
input => input === path.normalize('a/tsconfig.json'),
);

const tsconfigMatchCache = new ExpiringCache<string, string>(1);

Expand All @@ -111,7 +119,7 @@ describe('getProjectConfigFiles', () => {
true,
);

expect(actual).toEqual(['a/tsconfig.json']);
expect(actual).toEqual([path.normalize('a/tsconfig.json')]);
expect(mockExistsSync).toHaveBeenCalledTimes(6);
});
});
Expand All @@ -122,17 +130,19 @@ describe('getProjectConfigFiles', () => {

const actual = getProjectConfigFiles(parseSettings, true);

expect(actual).toEqual(['repos/repo/packages/package/tsconfig.json']);
expect(actual).toEqual([
path.normalize('repos/repo/packages/package/tsconfig.json'),
]);
});

it('returns a parent tsconfig.json when matched', () => {
mockExistsSync.mockImplementation(
filePath => filePath === 'repos/repo/tsconfig.json',
filePath => filePath === path.normalize('repos/repo/tsconfig.json'),
);

const actual = getProjectConfigFiles(parseSettings, true);

expect(actual).toEqual(['repos/repo/tsconfig.json']);
expect(actual).toEqual([path.normalize('repos/repo/tsconfig.json')]);
});

it('throws when searching hits .', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('parseAndGenerateServices', () => {
filePath: join(PROJECT_DIR, 'notIncluded.ts'),
}),
).toThrow(
/project was set to `true` but couldn't find any tsconfig.json relative to '.+\/tests\/fixtures\/projectTrue\/notIncluded.ts' within '.+\/tests\/fixtures\/projectTrue'./,
/project was set to `true` but couldn't find any tsconfig.json relative to '.+[/\\]tests[/\\]fixtures[/\\]projectTrue[/\\]notIncluded.ts' within '.+[/\\]tests[/\\]fixtures[/\\]projectTrue'./,
);
});
});
Expand Down

0 comments on commit ff6b190

Please sign in to comment.