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

build: Allow using jest as a test framework #1955

Merged
merged 2 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 15 additions & 2 deletions tools/cdk-build-tools/bin/cdk-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import fs = require('fs');
import util = require('util');
import yargs = require('yargs');
import { shell } from '../lib/os';
import { cdkBuildOptions, configFilePath, hasIntegTests, hasOnlyAutogeneratedTests, unitTestFiles } from '../lib/package-info';
import { cdkBuildOptions, configFilePath, currentPackageJson, hasIntegTests, hasOnlyAutogeneratedTests, unitTestFiles } from '../lib/package-info';
import { Timers } from '../lib/timer';

async function main() {
const args = yargs
.env('CDK_TEST')
.usage('Usage: cdk-test')
.option('force', { type: 'boolean', alias: 'f', desc: 'Force a rebuild' })
.option('jest', {
type: 'string',
desc: 'Specify a different jest executable',
default: require.resolve('jest/bin/jest'),
defaultDescription: 'jest provided by node dependencies'
})
.option('nyc', {
type: 'string',
desc: 'Specify a different nyc executable',
Expand All @@ -31,7 +37,14 @@ async function main() {
}

const testFiles = await unitTestFiles();
if (testFiles.length > 0) {
const useJest = 'jest' in currentPackageJson();

if (useJest) {
if (testFiles.length > 0) {
throw new Error(`Jest is enabled, but ${testFiles.length} nodeunit tests were found!`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So a package must be entirely jest or nodeunit to work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We could allow both but would have to merge coverage data & the likes, which is possible but ugly as heck. I don't need this right now so not getting into this... We can do that later if there is a real value to it.

}
await shell([args.jest, '--testEnvironment=node', '--coverage'], timers);
} else if (testFiles.length > 0) {
const testCommand: string[] = [];

// We always run the tests, but include an 'nyc' run (for coverage)
Expand Down
Loading