Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgrain committed Jan 5, 2023
1 parent 2b3bd0b commit 0a745b2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
30 changes: 22 additions & 8 deletions packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,13 @@ export class IntegrationTests {

// Use the selected presets
if (!options.app && !options.testRegex) {
// Only case with multiple languages, i.e. the only time we need to check the special case
const ignoreUncompiledTypeScript = options.language?.includes('javascript') && options.language?.includes('typescript');

return this.discover({
testCases: this.getLanguagePresets(options.language),
...baseOptions,
});
}, ignoreUncompiledTypeScript);
}

// Only one of app or test-regex is set, with a single preset selected
Expand Down Expand Up @@ -247,11 +250,6 @@ export class IntegrationTests {
javascript: ['node {filePath}', ['^integ\\..*\\.js$']],
typescript: ['node -r ts-node/register {filePath}', ['^integ\\.(?!.*\\.d\\.ts$).*\\.ts$']],
python: [`${pythonExecutable()} {filePath}`, ['^integ_.*\\.py$']],
csharp: ['dotnet run --project {filePath}', ['^Integ.*\\.csproj$']],
fsharp: ['dotnet run --project {filePath}', ['^Integ.*\\.fsproj$']],
// these are still unconfirmed and need testing
go: ['go mod download && go run {filePath}', ['^integ_.*\\.go$']],
java: ['mvn -e -q compile exec:java', ['^Integ.*\\.java$']],
};

return languagePresets[language];
Expand Down Expand Up @@ -307,10 +305,10 @@ export class IntegrationTests {
* @param tests Tests to include or exclude, undefined means include all tests.
* @param exclude Whether the 'tests' list is inclusive or exclusive (inclusive by default).
*/
private async discover(options: IntegrationTestsDiscoveryOptions): Promise<IntegTest[]> {
private async discover(options: IntegrationTestsDiscoveryOptions, ignoreUncompiledTypeScript: boolean = false): Promise<IntegTest[]> {
const files = await this.readTree();

const discoveredTests = Object.entries(options.testCases)
const testCases = Object.entries(options.testCases)
.flatMap(([appCommand, patterns]) => files
.filter(fileName => patterns.some((pattern) => {
const regex = new RegExp(pattern);
Expand All @@ -323,9 +321,25 @@ export class IntegrationTests {
})),
);

const discoveredTests = ignoreUncompiledTypeScript ? this.filterUncompiledTypeScript(testCases) : testCases;

return this.filterTests(discoveredTests, options.tests, options.exclude);
}

private filterUncompiledTypeScript(testCases: IntegTest[]): IntegTest[] {
const jsTestCases = testCases.filter(t => t.fileName.endsWith('.js'));

return testCases
// Remove all TypeScript test cases (ending in .ts)
// for which a compiled version is present (same name, ending in .js)
.filter((tsCandidate) => {
if (!tsCandidate.fileName.endsWith('.ts')) {
return true;
}
return jsTestCases.findIndex(jsTest => jsTest.testName === tsCandidate.testName) === -1;
});
}

private async readTree(): Promise<string[]> {
const ret = new Array<string>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,19 @@ describe('IntegrationTests Discovery', () => {
});
});
});

describe('Same test file in JS and TS is only running JS', () => {
const cliOptions = {
language: ['javascript', 'typescript'],
};

test('find only JS files', async () => {
const integTests = await tests.fromCliOptions(cliOptions);

expect(integTests.length).toEqual(3);
expect(integTests[0].fileName).toEqual(expect.stringMatching(new RegExp('^.*test1\\.js$')));
expect(integTests[1].fileName).toEqual(expect.stringMatching(new RegExp('^.*test2\\.js$')));
expect(integTests[2].fileName).toEqual(expect.stringMatching(new RegExp('^.*test3\\.js$')));
});
});
});

0 comments on commit 0a745b2

Please sign in to comment.