Skip to content

Commit

Permalink
feat(schematics): run tests for affected apps
Browse files Browse the repository at this point in the history
Add support for affected:test that works similar to the e2e
target except it runs test instead.  Theoretically useful
for a CI process to run the unit tests based on the apps
affected by the change.

This is WIP towards Issue nrwl#416
  • Loading branch information
markphip committed Apr 11, 2018
1 parent 2a377fe commit e83c2d9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions e2e/schematics/command-line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ describe('Command line', () => {
'npm run affected:e2e -- --files="libs/mylib/index.ts"'
);
expect(e2e).toContain('should display welcome message');

const test = runCommand(
'npm run affected:test -- --files="libs/mylib/index.ts"'
);
expect(test).toContain('should display welcome message');
},
1000000
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"affected:apps": "./node_modules/.bin/nx affected apps",
"affected:build": "./node_modules/.bin/nx affected build",
"affected:e2e": "./node_modules/.bin/nx affected e2e",
"affected:test": "./node_modules/.bin/nx affected test",
"affected:dep-graph": "./node_modules/.bin/nx affected dep-graph",
"format": "./node_modules/.bin/nx format write",
"format:write": "./node_modules/.bin/nx format write",
Expand Down
13 changes: 13 additions & 0 deletions packages/schematics/migrations/20180410-adding-affected-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { updateJsonFile } from '../src/utils/fileutils';

export default {
description: 'Update npm scripts to use the nx command',
run: () => {
updateJsonFile('package.json', json => {
json.scripts = {
...json.scripts,
'affected:test': './node_modules/.bin/nx affected test'
};
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"affected:apps": "./node_modules/.bin/nx affected apps",
"affected:build": "./node_modules/.bin/nx affected build",
"affected:e2e": "./node_modules/.bin/nx affected e2e",
"affected:test": "./node_modules/.bin/nx affected test",
"affected:dep-graph": "./node_modules/.bin/nx affected dep-graph",
"format": "./node_modules/.bin/nx format write",
"format:write": "./node_modules/.bin/nx format write",
Expand Down
2 changes: 2 additions & 0 deletions packages/schematics/src/collection/workspace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ function updatePackageJson() {
packageJson.scripts['affected:build'] =
'./node_modules/.bin/nx affected build';
packageJson.scripts['affected:e2e'] = './node_modules/.bin/nx affected e2e';
packageJson.scripts['affected:test'] =
'./node_modules/.bin/nx affected test';

packageJson.scripts['affected:dep-graph'] =
'./node_modules/.bin/nx affected dep-graph';
Expand Down
9 changes: 6 additions & 3 deletions packages/schematics/src/command-line/affected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export function affected(args: string[]): void {
build(apps, rest);
break;
case 'e2e':
e2e(apps, rest);
runTests('e2e', apps, rest);
break;
case 'test':
runTests('test', apps, rest);
break;
case 'dep-graph':
generateGraph(yargsParser(rest), projects);
Expand Down Expand Up @@ -77,11 +80,11 @@ function build(apps: string[], rest: string[]) {
}
}

function e2e(apps: string[], rest: string[]) {
function runTests(type: string, apps: string[], rest: string[]) {
if (apps.length > 0) {
console.log(`Testing ${apps.join(', ')}`);
apps.forEach(app => {
execSync(`node ${ngPath()} e2e ${rest.join(' ')} -a=${app}`, {
execSync(`node ${ngPath()} ${type} ${rest.join(' ')} -a=${app}`, {
stdio: [0, 1, 2]
});
});
Expand Down

0 comments on commit e83c2d9

Please sign in to comment.