-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(integ-runner): support custom
--test-regex
to match integ test…
… files Co-authored-by: karakter98 <37190268+karakter98@users.noreply.github.com>
- Loading branch information
1 parent
e89f2e0
commit 67a17d4
Showing
5 changed files
with
213 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import * as path from 'path'; | ||
import { main } from '../lib/cli'; | ||
|
||
describe('CLI', () => { | ||
const currentCwd = process.cwd(); | ||
beforeAll(() => { | ||
process.chdir(path.join(__dirname, '..')); | ||
}); | ||
afterAll(() => { | ||
process.chdir(currentCwd); | ||
}); | ||
|
||
let stdoutMock: jest.SpyInstance; | ||
beforeEach(() => { | ||
stdoutMock = jest.spyOn(process.stdout, 'write').mockImplementation(() => { return true; }); | ||
}); | ||
afterEach(() => { | ||
stdoutMock.mockRestore(); | ||
}); | ||
|
||
test('find by default pattern', async () => { | ||
await main(['--list', '--directory=test/test-data']); | ||
|
||
// Expect nothing to be found since this directory doesn't contain files with the default pattern | ||
expect(stdoutMock.mock.calls).toEqual([['\n']]); | ||
}); | ||
|
||
test('find by custom pattern', async () => { | ||
await main(['--list', '--directory=test/test-data', '--test-regex="^xxxxx\..*\.js$"']); | ||
|
||
// Expect nothing to be found since this directory doesn't contain files with the default pattern | ||
expect(stdoutMock.mock.calls).toEqual([[ | ||
[ | ||
'xxxxx.integ-test1.js', | ||
'xxxxx.integ-test2.js', | ||
'xxxxx.test-with-new-assets-diff.js', | ||
'xxxxx.test-with-new-assets.js', | ||
'xxxxx.test-with-snapshot-assets-diff.js', | ||
'xxxxx.test-with-snapshot-assets.js', | ||
'xxxxx.test-with-snapshot.js', | ||
'', | ||
].join('\n'), | ||
]]); | ||
}); | ||
}); |
145 changes: 124 additions & 21 deletions
145
packages/@aws-cdk/integ-runner/test/runner/integration-tests.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,153 @@ | ||
import { writeFileSync } from 'fs'; | ||
import * as mockfs from 'mock-fs'; | ||
import { IntegrationTests } from '../../lib/runner/integration-tests'; | ||
|
||
describe('IntegrationTests', () => { | ||
const tests = new IntegrationTests('test'); | ||
let stderrMock: jest.SpyInstance; | ||
stderrMock = jest.spyOn(process.stderr, 'write').mockImplementation(() => { return true; }); | ||
|
||
beforeEach(() => { | ||
mockfs({ | ||
'test/test-data': { | ||
'integ.integ-test1.js': 'content', | ||
'integ.integ-test2.js': 'content', | ||
'integ.integ-test3.js': 'content', | ||
}, | ||
'other/other-data': { | ||
'integ.other-test1.js': 'content', | ||
}, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
mockfs.restore(); | ||
}); | ||
|
||
test('from cli args', async () => { | ||
const integTests = await tests.fromCliArgs(['test-data/integ.integ-test1.js']); | ||
describe('from cli args', () => { | ||
test('find all', async () => { | ||
const integTests = await tests.fromCliArgs(); | ||
|
||
expect(integTests.length).toEqual(3); | ||
expect(integTests[0].fileName).toEqual(expect.stringMatching(/integ.integ-test1.js$/)); | ||
expect(integTests[1].fileName).toEqual(expect.stringMatching(/integ.integ-test2.js$/)); | ||
expect(integTests[2].fileName).toEqual(expect.stringMatching(/integ.integ-test3.js$/)); | ||
}); | ||
|
||
expect(integTests.length).toEqual(1); | ||
expect(integTests[0].fileName).toEqual(expect.stringMatching(/integ.integ-test1.js$/)); | ||
}); | ||
|
||
test('from cli args, test not found', async () => { | ||
const integTests = await tests.fromCliArgs(['test-data/integ.integ-test16.js']); | ||
test('find named tests', async () => { | ||
const integTests = await tests.fromCliArgs({ tests: ['test-data/integ.integ-test1.js'] }); | ||
|
||
expect(integTests.length).toEqual(0); | ||
expect(stderrMock.mock.calls[0][0]).toContain( | ||
'No such integ test: test-data/integ.integ-test16.js', | ||
); | ||
expect(stderrMock.mock.calls[1][0]).toContain( | ||
'Available tests: test-data/integ.integ-test1.js test-data/integ.integ-test2.js test-data/integ.integ-test3.js', | ||
); | ||
expect(integTests.length).toEqual(1); | ||
expect(integTests[0].fileName).toEqual(expect.stringMatching(/integ.integ-test1.js$/)); | ||
}); | ||
|
||
|
||
test('test not found', async () => { | ||
const integTests = await tests.fromCliArgs({ tests: ['test-data/integ.integ-test16.js'] }); | ||
|
||
expect(integTests.length).toEqual(0); | ||
expect(stderrMock.mock.calls[0][0]).toContain( | ||
'No such integ test: test-data/integ.integ-test16.js', | ||
); | ||
expect(stderrMock.mock.calls[1][0]).toContain( | ||
'Available tests: test-data/integ.integ-test1.js test-data/integ.integ-test2.js test-data/integ.integ-test3.js', | ||
); | ||
}); | ||
|
||
test('exclude tests', async () => { | ||
const integTests = await tests.fromCliArgs({ tests: ['test-data/integ.integ-test1.js'], exclude: true }); | ||
|
||
const fileNames = integTests.map(test => test.fileName); | ||
expect(integTests.length).toEqual(2); | ||
expect(fileNames).not.toContain( | ||
'test/test-data/integ.integ-test1.js', | ||
); | ||
}); | ||
|
||
test('match regex', async () => { | ||
const integTests = await tests.fromCliArgs({ testRegex: ['1\.js$', '2\.js'] }); | ||
|
||
expect(integTests.length).toEqual(2); | ||
expect(integTests[0].fileName).toEqual(expect.stringMatching(/integ.integ-test1.js$/)); | ||
expect(integTests[1].fileName).toEqual(expect.stringMatching(/integ.integ-test2.js$/)); | ||
}); | ||
|
||
test('match regex with path', async () => { | ||
const otherTestDir = new IntegrationTests('.'); | ||
const integTests = await otherTestDir.fromCliArgs({ testRegex: ['other-data/integ\..*\.js$'] }); | ||
|
||
expect(integTests.length).toEqual(1); | ||
expect(integTests[0].fileName).toEqual(expect.stringMatching(/integ.other-test1.js$/)); | ||
}); | ||
}); | ||
|
||
test('from cli args, exclude', async () => { | ||
const integTests = await tests.fromCliArgs(['test-data/integ.integ-test1.js'], true); | ||
describe('from file', () => { | ||
const configFile = 'integ.config.json'; | ||
const writeConfig = (settings: any, fileName = configFile) => { | ||
writeFileSync(fileName, JSON.stringify(settings, null, 2), { encoding: 'utf-8' }); | ||
}; | ||
|
||
const fileNames = integTests.map(test => test.fileName); | ||
expect(integTests.length).toEqual(2); | ||
expect(fileNames).not.toContain( | ||
'test/test-data/integ.integ-test1.js', | ||
); | ||
test('find all', async () => { | ||
writeConfig({}); | ||
const integTests = await tests.fromFile(configFile); | ||
|
||
expect(integTests.length).toEqual(3); | ||
expect(integTests[0].fileName).toEqual(expect.stringMatching(/integ.integ-test1.js$/)); | ||
expect(integTests[1].fileName).toEqual(expect.stringMatching(/integ.integ-test2.js$/)); | ||
expect(integTests[2].fileName).toEqual(expect.stringMatching(/integ.integ-test3.js$/)); | ||
}); | ||
|
||
|
||
test('find named tests', async () => { | ||
writeConfig({ tests: ['test-data/integ.integ-test1.js'] }); | ||
const integTests = await tests.fromFile(configFile); | ||
|
||
expect(integTests.length).toEqual(1); | ||
expect(integTests[0].fileName).toEqual(expect.stringMatching(/integ.integ-test1.js$/)); | ||
}); | ||
|
||
|
||
test('test not found', async () => { | ||
writeConfig({ tests: ['test-data/integ.integ-test16.js'] }); | ||
const integTests = await tests.fromFile(configFile); | ||
|
||
expect(integTests.length).toEqual(0); | ||
expect(stderrMock.mock.calls[0][0]).toContain( | ||
'No such integ test: test-data/integ.integ-test16.js', | ||
); | ||
expect(stderrMock.mock.calls[1][0]).toContain( | ||
'Available tests: test-data/integ.integ-test1.js test-data/integ.integ-test2.js test-data/integ.integ-test3.js', | ||
); | ||
}); | ||
|
||
test('exclude tests', async () => { | ||
writeConfig({ tests: ['test-data/integ.integ-test1.js'], exclude: true }); | ||
const integTests = await tests.fromFile(configFile); | ||
|
||
const fileNames = integTests.map(test => test.fileName); | ||
expect(integTests.length).toEqual(2); | ||
expect(fileNames).not.toContain( | ||
'test/test-data/integ.integ-test1.js', | ||
); | ||
}); | ||
|
||
test('match regex', async () => { | ||
writeConfig({ testRegex: ['1\.js$', '2\.js'] }); | ||
const integTests = await tests.fromFile(configFile); | ||
|
||
expect(integTests.length).toEqual(2); | ||
expect(integTests[0].fileName).toEqual(expect.stringMatching(/integ.integ-test1.js$/)); | ||
expect(integTests[1].fileName).toEqual(expect.stringMatching(/integ.integ-test2.js$/)); | ||
}); | ||
|
||
test('match regex with path', async () => { | ||
writeConfig({ testRegex: ['other-data/integ\..*\.js$'] }); | ||
const otherTestDir = new IntegrationTests('.'); | ||
const integTests = await otherTestDir.fromFile(configFile); | ||
|
||
expect(integTests.length).toEqual(1); | ||
expect(integTests[0].fileName).toEqual(expect.stringMatching(/integ.other-test1.js$/)); | ||
}); | ||
}); | ||
}); |