Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(integ-runner): support --language presets for JavaScript, TypeScript, Python and Go #22058

Merged
merged 5 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(integ-runner): ignore uncompiled TypeScript files if a compiled …
…version of the test is present
  • Loading branch information
mrgrain committed Jan 5, 2023
commit 2d9718996925b9fbd7d4e8790470c87dd649b849
25 changes: 22 additions & 3 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 @@ -302,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 @@ -318,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$')));
});
});
});