diff --git a/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts b/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts index 970dc1c4fd6f3..8b0dd600980ba 100644 --- a/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts +++ b/packages/@aws-cdk/integ-runner/lib/runner/integration-tests.ts @@ -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 @@ -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]; @@ -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 { + private async discover(options: IntegrationTestsDiscoveryOptions, ignoreUncompiledTypeScript: boolean = false): Promise { 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); @@ -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 { const ret = new Array(); diff --git a/packages/@aws-cdk/integ-runner/test/runner/integration-tests.test.ts b/packages/@aws-cdk/integ-runner/test/runner/integration-tests.test.ts index 0057986775416..11c5af79756e5 100644 --- a/packages/@aws-cdk/integ-runner/test/runner/integration-tests.test.ts +++ b/packages/@aws-cdk/integ-runner/test/runner/integration-tests.test.ts @@ -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$'))); + }); + }); });