refactor(testing): separate jest to @nrwl/jest

This commit is contained in:
Jason Jean 2019-04-15 13:11:34 -04:00 committed by Victor Savkin
parent 9ee487d20f
commit 625b2837a8
49 changed files with 316 additions and 207 deletions

View File

@ -4,6 +4,8 @@ tmp
node_modules node_modules
/package.json /package.json
packages/schematics/src/collection/**/files/**/*.json packages/schematics/src/collection/**/files/**/*.json
packages/react/src/schematics/**/files/**/*.json
packages/jest/src/schematics/**/files/**/*.json
/.vscode /.vscode
/.idea /.idea
/.github /.github

View File

@ -1,4 +1,4 @@
# jest-project [hidden] # jest-project
Add Jest configuration to a project Add Jest configuration to a project
@ -19,7 +19,7 @@ The name of the project.
### setupFile ### setupFile
Default: `angular` Default: `none`
Type: `string` Type: `string`

View File

@ -1,10 +1,10 @@
# jest [hidden] # ng-add [hidden]
Add Jest configuration to the workspace Add Jest configuration to the workspace
## Usage ## Usage
```bash ```bash
ng generate jest ... ng generate ng-add ...
``` ```

View File

@ -1,39 +1,23 @@
import { import { newLib, runCLIAsync, newApp, ensureProject, uniq } from '../utils';
newProject,
runCLI,
newLib,
runCLIAsync,
newApp,
copyMissingPackages,
ensureProject,
uniq
} from '../utils';
describe('Jest', () => { describe('Jest', () => {
it('should be able to generate a testable library using jest', async done => { it('should be able test projects using jest', async done => {
ensureProject(); ensureProject();
const mylib = uniq('mylib'); const mylib = uniq('mylib');
const myapp = uniq('myapp');
newApp(`${myapp} --unit-test-runner jest --framework=angular`);
newLib(`${mylib} --unit-test-runner jest --framework=angular`); newLib(`${mylib} --unit-test-runner jest --framework=angular`);
await Promise.all([ await Promise.all([
runCLIAsync(`generate service test --project ${myapp}`),
runCLIAsync(`generate component test --project ${myapp}`),
runCLIAsync(`generate service test --project ${mylib}`), runCLIAsync(`generate service test --project ${mylib}`),
runCLIAsync(`generate component test --project ${mylib}`) runCLIAsync(`generate component test --project ${mylib}`)
]); ]);
const jestResult = await runCLIAsync(`test ${mylib}`); const appResult = await runCLIAsync(`test ${myapp}`);
expect(jestResult.stderr).toContain('Test Suites: 3 passed, 3 total'); expect(appResult.stderr).toContain('Test Suites: 3 passed, 3 total');
const libResult = await runCLIAsync(`test ${mylib}`);
expect(libResult.stderr).toContain('Test Suites: 3 passed, 3 total');
done(); done();
}, 45000); }, 45000);
it('should be able to generate a testable application using jest', async () => {
ensureProject();
const myapp = uniq('myapp');
newApp(`${myapp} --unit-test-runner jest --framework=angular`);
await Promise.all([
runCLIAsync(`generate service test --project ${myapp}`),
runCLIAsync(`generate component test --project ${myapp}`)
]);
const jestResult = await runCLIAsync(`test ${myapp}`);
expect(jestResult.stderr).toContain('Test Suites: 3 passed, 3 total');
}, 450000);
}); });

View File

@ -1,14 +1,9 @@
import { import {
newApp, newApp,
newLib, newLib,
newProject,
readJson,
runCLI, runCLI,
updateFile, updateFile,
exists, exists,
runNgNew,
cleanup,
copyMissingPackages,
getSize, getSize,
expectTestsPass, expectTestsPass,
runCLIAsync, runCLIAsync,
@ -19,8 +14,11 @@ import {
import { toClassName } from '@nrwl/schematics/src/utils/name-utils'; import { toClassName } from '@nrwl/schematics/src/utils/name-utils';
describe('Nrwl Workspace', () => { describe('Nrwl Workspace', () => {
it('should work', async () => { beforeEach(() => {
ensureProject(); ensureProject();
});
it('should work', async () => {
const myapp = uniq('myapp'); const myapp = uniq('myapp');
const mylib = uniq('mylib'); const mylib = uniq('mylib');
newApp(`${myapp} --directory=myDir`); newApp(`${myapp} --directory=myDir`);
@ -73,7 +71,6 @@ describe('Nrwl Workspace', () => {
}, 1000000); }, 1000000);
it('should support router config generation (lazy)', async () => { it('should support router config generation (lazy)', async () => {
ensureProject();
const myapp = uniq('myapp'); const myapp = uniq('myapp');
const mylib = uniq('mylib'); const mylib = uniq('mylib');
newApp(`${myapp} --directory=myDir --routing`); newApp(`${myapp} --directory=myDir --routing`);
@ -88,7 +85,6 @@ describe('Nrwl Workspace', () => {
}, 1000000); }, 1000000);
it('should support router config generation (eager)', async () => { it('should support router config generation (eager)', async () => {
ensureProject();
const myapp = uniq('myapp'); const myapp = uniq('myapp');
newApp(`${myapp} --directory=myDir --routing`); newApp(`${myapp} --directory=myDir --routing`);
const mylib = uniq('mylib'); const mylib = uniq('mylib');

View File

@ -25,6 +25,8 @@ export function newProject(): void {
if (!directoryExists('./tmp/proj_backup')) { if (!directoryExists('./tmp/proj_backup')) {
runNgNew('--collection=@nrwl/schematics --npmScope=proj', true); runNgNew('--collection=@nrwl/schematics --npmScope=proj', true);
copyMissingPackages(); copyMissingPackages();
runCLI('add @nrwl/jest');
runCLI('add @nrwl/react');
execSync('mv ./tmp/proj ./tmp/proj_backup'); execSync('mv ./tmp/proj ./tmp/proj_backup');
} }
execSync('cp -a ./tmp/proj_backup ./tmp/proj'); execSync('cp -a ./tmp/proj_backup ./tmp/proj');

View File

@ -6,7 +6,7 @@
"main": "index.js", "main": "index.js",
"private": true, "private": true,
"scripts": { "scripts": {
"build": "./scripts/build.sh", "build": "./scripts/package.sh --local",
"commit": "git-cz", "commit": "git-cz",
"checkcommit": "node ./scripts/commit-lint.js", "checkcommit": "node ./scripts/commit-lint.js",
"e2e": "./scripts/e2e.sh", "e2e": "./scripts/e2e.sh",

View File

@ -21,11 +21,6 @@
"schema": "./web/dev-server/schema.json", "schema": "./web/dev-server/schema.json",
"description": "Serve a web application" "description": "Serve a web application"
}, },
"jest": {
"class": "./jest/jest.builder",
"schema": "./jest/schema.json",
"description": "Run Jest unit tests"
},
"cypress": { "cypress": {
"class": "./cypress/cypress.builder", "class": "./cypress/cypress.builder",
"schema": "./cypress/schema.json", "schema": "./cypress/schema.json",

View File

@ -0,0 +1,10 @@
{
"$schema": "@angular-devkit/architect/src/builders-schema.json",
"builders": {
"jest": {
"class": "./src/builders/jest/jest.builder",
"schema": "./src/builders/jest/schema.json",
"description": "Run Jest unit tests"
}
}
}

View File

@ -0,0 +1,17 @@
{
"name": "Nx Jest",
"version": "0.1",
"schematics": {
"ng-add": {
"factory": "./src/schematics/ng-add/ng-add",
"schema": "./src/schematics/ng-add/schema.json",
"description": "Add Jest configuration to the workspace",
"hidden": true
},
"jest-project": {
"factory": "./src/schematics/jest-project/jest-project",
"schema": "./src/schematics/jest-project/schema.json",
"description": "Add Jest configuration to a project"
}
}
}

0
packages/jest/index.ts Normal file
View File

View File

@ -0,0 +1,3 @@
{
"schematics": {}
}

View File

@ -0,0 +1,41 @@
{
"name": "@nrwl/jest",
"version": "0.0.1",
"description": "Jest plugin for Nx",
"repository": {
"type": "git",
"url": "git+https://github.com/nrwl/nx.git"
},
"keywords": [
"Jest",
"Unit Testing",
"Workspace",
"Monorepo",
"Schematics",
"Nx",
"Angular CLI"
],
"main": "index.js",
"types": "index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
"bugs": {
"url": "https://github.com/nrwl/nx/issues"
},
"homepage": "https://nx.dev",
"schematics": "./collection.json",
"builders": "./builders.json",
"ng-update": {
"requirements": {},
"migrations": "./migrations.json"
},
"peerDependencies": {
"@nrwl/schematics": "*"
},
"dependencies": {
"@angular-devkit/architect": "~0.13.1",
"@angular-devkit/core": "~7.3.1",
"@angular-devkit/schematics": "~7.3.1",
"rxjs": "6.3.3"
}
}

View File

@ -1,5 +1,5 @@
{ {
"title": "Jest Target", "title": "Jest Builder",
"description": "Jest target options for Build Facade", "description": "Jest target options for Build Facade",
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -1,6 +1,7 @@
import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { Tree, VirtualTree } from '@angular-devkit/schematics';
import { createEmptyWorkspace, runSchematic } from '../../utils/testing-utils'; import { createEmptyWorkspace } from '@nrwl/schematics/testing';
import { readJsonInTree } from '@nrwl/schematics/src/utils/ast-utils'; import { readJsonInTree, updateJsonInTree } from '@nrwl/schematics';
import { runSchematic, callRule } from '../../utils/testing';
describe('jestProject', () => { describe('jestProject', () => {
let appTree: Tree; let appTree: Tree;
@ -8,12 +9,31 @@ describe('jestProject', () => {
beforeEach(async () => { beforeEach(async () => {
appTree = new VirtualTree(); appTree = new VirtualTree();
appTree = createEmptyWorkspace(appTree); appTree = createEmptyWorkspace(appTree);
appTree = await runSchematic( appTree = await callRule(
'lib', updateJsonInTree('angular.json', json => {
{ json.projects.lib1 = {
name: 'lib1', root: 'libs/lib1',
unitTestRunner: 'none' architect: {
}, lint: {
builder: '@angular-devkit/build-angular:tslint',
options: {
tsConfig: []
}
}
}
};
return json;
}),
appTree
);
appTree = await callRule(
updateJsonInTree('libs/lib1/tsconfig.json', json => {
return {
compilerOptions: {
types: []
}
};
}),
appTree appTree
); );
}); });
@ -22,7 +42,8 @@ describe('jestProject', () => {
const resultTree = await runSchematic( const resultTree = await runSchematic(
'jest-project', 'jest-project',
{ {
project: 'lib1' project: 'lib1',
setupFile: 'angular'
}, },
appTree appTree
); );
@ -35,13 +56,14 @@ describe('jestProject', () => {
const resultTree = await runSchematic( const resultTree = await runSchematic(
'jest-project', 'jest-project',
{ {
project: 'lib1' project: 'lib1',
setupFile: 'angular'
}, },
appTree appTree
); );
const angularJson = readJsonInTree(resultTree, 'angular.json'); const angularJson = readJsonInTree(resultTree, 'angular.json');
expect(angularJson.projects.lib1.architect.test).toEqual({ expect(angularJson.projects.lib1.architect.test).toEqual({
builder: '@nrwl/builders:jest', builder: '@nrwl/jest:jest',
options: { options: {
jestConfig: 'libs/lib1/jest.config.js', jestConfig: 'libs/lib1/jest.config.js',
setupFile: 'libs/lib1/src/test-setup.ts', setupFile: 'libs/lib1/src/test-setup.ts',
@ -91,7 +113,8 @@ describe('jestProject', () => {
const resultTree = await runSchematic( const resultTree = await runSchematic(
'jest-project', 'jest-project',
{ {
project: 'lib1' project: 'lib1',
setupFile: 'angular'
}, },
appTree appTree
); );
@ -168,21 +191,6 @@ describe('jestProject', () => {
).toBeDefined(); ).toBeDefined();
}); });
}); });
describe('not angular', () => {
it('should add ts-jest dependency', async () => {
const resultTree = await runSchematic(
'jest-project',
{
project: 'lib1',
setupFile: 'web-components'
},
appTree
);
const packageJson = readJsonInTree(resultTree, 'package.json');
expect(packageJson.devDependencies['ts-jest']).toBeDefined();
});
});
}); });
describe('--skip-setup-file', () => { describe('--skip-setup-file', () => {

View File

@ -9,18 +9,16 @@ import {
move, move,
template, template,
noop, noop,
filter, filter
schematic
} from '@angular-devkit/schematics'; } from '@angular-devkit/schematics';
import { readJsonInTree, updateJsonInTree } from '@nrwl/schematics';
import { import {
getProjectConfig, getProjectConfig,
readJsonInTree,
updateJsonInTree,
addDepsToPackageJson addDepsToPackageJson
} from '../../utils/ast-utils'; } from '@nrwl/schematics/src/utils/ast-utils';
import { offsetFromRoot } from '../../utils/common'; import { offsetFromRoot } from '@nrwl/schematics/src/utils/common';
import { join, normalize } from '@angular-devkit/core'; import { join, normalize } from '@angular-devkit/core';
import { jestPresetAngularVersion, tsJestversion } from '../../lib-versions'; import { jestPresetAngularVersion } from '../../utils/versions';
export interface JestProjectSchema { export interface JestProjectSchema {
project: string; project: string;
@ -51,8 +49,16 @@ function generateFiles(options: JestProjectSchema): Rule {
} }
function updateTsConfig(options: JestProjectSchema): Rule { function updateTsConfig(options: JestProjectSchema): Rule {
return (host: Tree, context: SchematicContext) => { return (host: Tree) => {
const projectConfig = getProjectConfig(host, options.project); const projectConfig = getProjectConfig(host, options.project);
if (!host.exists(join(projectConfig.root, 'tsconfig.json'))) {
throw new Error(
`Expected ${join(
projectConfig.root,
'tsconfig.json'
)} to exist. Please create one.`
);
}
return updateJsonInTree(join(projectConfig.root, 'tsconfig.json'), json => { return updateJsonInTree(join(projectConfig.root, 'tsconfig.json'), json => {
return { return {
...json, ...json,
@ -71,7 +77,7 @@ function updateAngularJson(options: JestProjectSchema): Rule {
return updateJsonInTree('angular.json', json => { return updateJsonInTree('angular.json', json => {
const projectConfig = json.projects[options.project]; const projectConfig = json.projects[options.project];
projectConfig.architect.test = { projectConfig.architect.test = {
builder: '@nrwl/builders:jest', builder: '@nrwl/jest:jest',
options: { options: {
jestConfig: join(normalize(projectConfig.root), 'jest.config.js'), jestConfig: join(normalize(projectConfig.root), 'jest.config.js'),
tsConfig: join(normalize(projectConfig.root), 'tsconfig.spec.json') tsConfig: join(normalize(projectConfig.root), 'tsconfig.spec.json')
@ -97,8 +103,6 @@ function addDependencies(options: JestProjectSchema): Rule {
const devDeps = {}; const devDeps = {};
if (options.setupFile === 'angular') { if (options.setupFile === 'angular') {
devDeps['jest-preset-angular'] = jestPresetAngularVersion; devDeps['jest-preset-angular'] = jestPresetAngularVersion;
} else {
devDeps['ts-jest'] = tsJestversion;
} }
return addDepsToPackageJson({}, devDeps); return addDepsToPackageJson({}, devDeps);
} }
@ -113,8 +117,10 @@ function check(options: JestProjectSchema): Rule {
} }
const packageJson = readJsonInTree(host, 'package.json'); const packageJson = readJsonInTree(host, 'package.json');
if (!packageJson.devDependencies.jest) { if (!packageJson.devDependencies.jest) {
return schematic('jest', {}); context.logger.warn(`"jest" is not installed as a dependency.`);
context.logger.info(`Add "jest" via "ng add @nrwl/jest"`);
} }
return host;
}; };
} }

View File

@ -1,7 +1,7 @@
{ {
"$schema": "http://json-schema.org/schema", "$schema": "http://json-schema.org/schema",
"id": "SchematicsNxJestProject", "id": "NxJestProject",
"title": "Create Jest Configuration for a project", "title": "Add Jest Configuration to a project",
"type": "object", "type": "object",
"properties": { "properties": {
"project": { "project": {
@ -21,7 +21,7 @@
"type": "string", "type": "string",
"enum": ["none", "angular", "web-components"], "enum": ["none", "angular", "web-components"],
"description": "The setup file to be generated", "description": "The setup file to be generated",
"default": "angular" "default": "none"
}, },
"skipSerializers": { "skipSerializers": {
"type": "boolean", "type": "boolean",

View File

@ -3,7 +3,7 @@ module.exports = {
transform: { transform: {
'^.+\\.(ts|js|html)$': 'ts-jest' '^.+\\.(ts|js|html)$': 'ts-jest'
}, },
resolver: '@nrwl/builders/plugins/jest/resolver', resolver: '@nrwl/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'html'], moduleFileExtensions: ['ts', 'js', 'html'],
collectCoverage: true, collectCoverage: true,
coverageReporters: ['html'] coverageReporters: ['html']

View File

@ -1,12 +1,7 @@
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path';
import { Tree, VirtualTree } from '@angular-devkit/schematics'; import { Tree, VirtualTree } from '@angular-devkit/schematics';
import { import { createEmptyWorkspace } from '@nrwl/schematics/testing';
createEmptyWorkspace,
createLib,
runSchematic
} from '../../utils/testing-utils';
import { readJsonInTree } from '@nrwl/schematics/src/utils/ast-utils'; import { readJsonInTree } from '@nrwl/schematics/src/utils/ast-utils';
import { runSchematic } from '../../utils/testing';
describe('jest', () => { describe('jest', () => {
let appTree: Tree; let appTree: Tree;
@ -17,15 +12,16 @@ describe('jest', () => {
}); });
it('should generate files', async () => { it('should generate files', async () => {
const resultTree = await runSchematic('jest', {}, appTree); const resultTree = await runSchematic('ng-add', {}, appTree);
expect(resultTree.exists('jest.config.js')).toBeTruthy(); expect(resultTree.exists('jest.config.js')).toBeTruthy();
}); });
it('should add dependencies', async () => { it('should add dependencies', async () => {
const resultTree = await runSchematic('jest', {}, appTree); const resultTree = await runSchematic('ng-add', {}, appTree);
const packageJson = readJsonInTree(resultTree, 'package.json'); const packageJson = readJsonInTree(resultTree, 'package.json');
expect(packageJson.devDependencies.jest).toBeDefined(); expect(packageJson.devDependencies.jest).toBeDefined();
expect(packageJson.devDependencies['@nrwl/builders']).toBeDefined(); expect(packageJson.devDependencies['@nrwl/jest']).toBeDefined();
expect(packageJson.devDependencies['@types/jest']).toBeDefined(); expect(packageJson.devDependencies['@types/jest']).toBeDefined();
expect(packageJson.devDependencies['ts-jest']).toBeDefined();
}); });
}); });

View File

@ -0,0 +1,33 @@
import { mergeWith, chain, url } from '@angular-devkit/schematics';
import {
addDepsToPackageJson,
updateJsonInTree
} from '@nrwl/schematics/src/utils/ast-utils';
import {
jestVersion,
jestTypesVersion,
tsJestVersion,
nxVersion
} from '../../utils/versions';
import { Rule } from '@angular-devkit/schematics';
const updatePackageJson = chain([
addDepsToPackageJson(
{},
{
'@nrwl/jest': nxVersion,
jest: jestVersion,
'@types/jest': jestTypesVersion,
'ts-jest': tsJestVersion
}
),
updateJsonInTree('package.json', json => {
json.dependencies = json.dependencies || {};
delete json.dependencies['@nrwl/jest'];
return json;
})
]);
export default function(): Rule {
return chain([mergeWith(url('./files')), updatePackageJson]);
}

View File

@ -1,7 +1,7 @@
{ {
"$schema": "http://json-schema.org/schema", "$schema": "http://json-schema.org/schema",
"id": "SchematicsNxJest", "id": "NxJestNgAdd",
"title": "Create Jest Configuration for the workspace", "title": "Add Jest Configuration to a workspace",
"type": "object", "type": "object",
"properties": {}, "properties": {},
"required": [] "required": []

View File

@ -0,0 +1,16 @@
import { join } from 'path';
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import { Tree, Rule } from '@angular-devkit/schematics';
const testRunner = new SchematicTestRunner(
'@nrwl/jest',
join(__dirname, '../../collection.json')
);
export function runSchematic(schematicName: string, options: any, tree: Tree) {
return testRunner.runSchematicAsync(schematicName, options, tree).toPromise();
}
export function callRule(rule: Rule, tree: Tree) {
return testRunner.callRule(rule, tree).toPromise();
}

View File

@ -0,0 +1,5 @@
export const nxVersion = '*';
export const jestVersion = '24.1.0';
export const jestTypesVersion = '24.0.9';
export const jestPresetAngularVersion = '7.0.0';
export const tsJestVersion = '24.0.0';

View File

@ -32,6 +32,7 @@
}, },
"dependencies": { "dependencies": {
"@angular-devkit/core": "~7.3.1", "@angular-devkit/core": "~7.3.1",
"@angular-devkit/schematics": "~7.3.1" "@angular-devkit/schematics": "~7.3.1",
"@nrwl/jest": "*"
} }
} }

View File

@ -189,7 +189,7 @@ export default function(schema: Schema): Rule {
}) })
: noop(), : noop(),
options.unitTestRunner === 'jest' options.unitTestRunner === 'jest'
? externalSchematic('@nrwl/schematics', 'jest-project', { ? externalSchematic('@nrwl/jest', 'jest-project', {
project: options.name, project: options.name,
supportTsx: true, supportTsx: true,
skipSerializers: true, skipSerializers: true,

View File

@ -101,7 +101,7 @@ export default function(schema: Schema): Rule {
addProject(options), addProject(options),
updateNxJson(options), updateNxJson(options),
options.unitTestRunner !== 'none' options.unitTestRunner !== 'none'
? externalSchematic('@nrwl/schematics', 'jest-project', { ? externalSchematic('@nrwl/jest', 'jest-project', {
project: options.name, project: options.name,
setupFile: 'none', setupFile: 'none',
supportTsx: true, supportTsx: true,

View File

@ -1,7 +1,14 @@
import { Rule, chain } from '@angular-devkit/schematics'; import {
Rule,
chain,
externalSchematic,
noop,
Tree
} from '@angular-devkit/schematics';
import { import {
addDepsToPackageJson, addDepsToPackageJson,
updateJsonInTree updateJsonInTree,
readJsonInTree
} from '@nrwl/schematics/src/utils/ast-utils'; } from '@nrwl/schematics/src/utils/ast-utils';
import { import {
frameworkVersion, frameworkVersion,
@ -35,6 +42,22 @@ function moveDependency(): Rule {
}); });
} }
export default function() { function addJest(): Rule {
return chain([addDependencies(), moveDependency()]); return (host: Tree) => {
const packageJson = readJsonInTree(host, 'package.json');
return !packageJson.devDependencies['@nrwl/jest']
? externalSchematic(
'@nrwl/jest',
'ng-add',
{},
{
interactive: false
}
)
: noop();
};
}
export default function() {
return chain([addJest(), addDependencies(), moveDependency()]);
} }

View File

@ -50,20 +50,6 @@
"description": "Add NgRx support to a module" "description": "Add NgRx support to a module"
}, },
"jest": {
"factory": "./collection/jest",
"schema": "./collection/jest/schema.json",
"description": "Add Jest configuration to the workspace",
"hidden": true
},
"jest-project": {
"factory": "./collection/jest-project",
"schema": "./collection/jest-project/schema.json",
"description": "Add Jest configuration to a project",
"hidden": true
},
"karma": { "karma": {
"factory": "./collection/karma", "factory": "./collection/karma",
"schema": "./collection/karma/schema.json", "schema": "./collection/karma/schema.json",

View File

@ -515,7 +515,7 @@ export default function(schema: Schema): Rule {
updateDependencies(options), updateDependencies(options),
updateLinting(options), updateLinting(options),
options.unitTestRunner === 'jest' options.unitTestRunner === 'jest'
? schematic('jest-project', { ? externalSchematic('@nrwl/jest', 'jest-project', {
project: options.name, project: options.name,
supportTsx: false, supportTsx: false,
skipSerializers: options.framework !== Framework.Angular, skipSerializers: options.framework !== Framework.Angular,

View File

@ -3,7 +3,7 @@
"fixturesFolder": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/src/fixtures", "fixturesFolder": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/src/fixtures",
"integrationFolder": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/src/integration", "integrationFolder": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/src/integration",
"pluginsFile": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/src/plugins/index.js", "pluginsFile": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/src/plugins/index.js",
"supportFile": false, "supportFile": false,
"video": true, "video": true,
"videosFolder": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/videos", "videosFolder": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/videos",
"screenshotsFolder": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/screenshots", "screenshotsFolder": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/screenshots",

View File

@ -4,7 +4,5 @@
"sourceMap": false, "sourceMap": false,
"outDir": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/src" "outDir": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/src"
}, },
"include": [ "include": ["src/**/*.ts"]
"src/**/*.ts"
]
} }

View File

@ -1,17 +0,0 @@
import { mergeWith, chain, url } from '@angular-devkit/schematics';
import { addDepsToPackageJson } from '../../utils/ast-utils';
import { jestVersion, jestTypesVersion, nxVersion } from '../../lib-versions';
import { Rule } from '@angular-devkit/schematics';
const updatePackageJson = addDepsToPackageJson(
{},
{
'@nrwl/builders': nxVersion,
jest: jestVersion,
'@types/jest': jestTypesVersion
}
);
export default function(): Rule {
return chain([mergeWith(url('./files')), updatePackageJson]);
}

View File

@ -450,7 +450,7 @@ export default function(schema: Schema): Rule {
updateProject(options), updateProject(options),
updateTsConfig(options), updateTsConfig(options),
options.unitTestRunner === 'jest' options.unitTestRunner === 'jest'
? schematic('jest-project', { ? externalSchematic('@nrwl/jest', 'jest-project', {
project: options.name, project: options.name,
setupFile: setupFile:
options.framework === Framework.Angular ? 'angular' : 'none', options.framework === Framework.Angular ? 'angular' : 'none',

View File

@ -9,7 +9,8 @@ import {
mergeWith, mergeWith,
apply, apply,
url, url,
template template,
externalSchematic
} from '@angular-devkit/schematics'; } from '@angular-devkit/schematics';
import { join, normalize, Path } from '@angular-devkit/core'; import { join, normalize, Path } from '@angular-devkit/core';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
@ -222,7 +223,7 @@ export default function(schema: Schema): Rule {
updateNxJson(options), updateNxJson(options),
options.framework !== 'none' ? createSourceCode(options) : noop(), options.framework !== 'none' ? createSourceCode(options) : noop(),
options.unitTestRunner === 'jest' options.unitTestRunner === 'jest'
? schematic('jest-project', { ? externalSchematic('@nrwl/jest', 'jest-project', {
project: options.name, project: options.name,
setupFile: 'none', setupFile: 'none',
skipSerializers: true skipSerializers: true

View File

@ -27,8 +27,7 @@
"help": "./node_modules/.bin/nx help" "help": "./node_modules/.bin/nx help"
}, },
"private": true, "private": true,
"dependencies": { "dependencies": {},
},
"devDependencies": { "devDependencies": {
"@angular/cli": "<%= angularCliVersion %>", "@angular/cli": "<%= angularCliVersion %>",
"@nrwl/schematics": "<%= schematicsVersion %>", "@nrwl/schematics": "<%= schematicsVersion %>",

View File

@ -1,7 +1,5 @@
{ {
"rulesDirectory": [ "rulesDirectory": ["node_modules/@nrwl/schematics/src/tslint"],
"node_modules/@nrwl/schematics/src/tslint"
],
"rules": { "rules": {
"arrow-return-shorthand": true, "arrow-return-shorthand": true,
"callable-types": true, "callable-types": true,
@ -10,10 +8,7 @@
"severity": "warn" "severity": "warn"
}, },
"forin": true, "forin": true,
"import-blacklist": [ "import-blacklist": [true, "rxjs/Rx"],
true,
"rxjs/Rx"
],
"interface-over-type-literal": true, "interface-over-type-literal": true,
"member-access": false, "member-access": false,
"member-ordering": [ "member-ordering": [
@ -29,24 +24,14 @@
], ],
"no-arg": true, "no-arg": true,
"no-bitwise": true, "no-bitwise": true,
"no-console": [ "no-console": [true, "debug", "info", "time", "timeEnd", "trace"],
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-construct": true, "no-construct": true,
"no-debugger": true, "no-debugger": true,
"no-duplicate-super": true, "no-duplicate-super": true,
"no-empty": false, "no-empty": false,
"no-empty-interface": true, "no-empty-interface": true,
"no-eval": true, "no-eval": true,
"no-inferrable-types": [ "no-inferrable-types": [true, "ignore-params"],
true,
"ignore-params"
],
"no-misused-new": true, "no-misused-new": true,
"no-non-null-assertion": true, "no-non-null-assertion": true,
"no-shadowed-variable": true, "no-shadowed-variable": true,
@ -60,10 +45,7 @@
"object-literal-sort-keys": false, "object-literal-sort-keys": false,
"prefer-const": true, "prefer-const": true,
"radix": true, "radix": true,
"triple-equals": [ "triple-equals": [true, "allow-null-check"],
true,
"allow-null-check"
],
"unified-signatures": true, "unified-signatures": true,
"variable-name": false, "variable-name": false,

View File

@ -10,10 +10,6 @@ export const latestMigration = '20180507-create-nx-json';
export const prettierVersion = '1.16.4'; export const prettierVersion = '1.16.4';
export const typescriptVersion = '3.2.2'; export const typescriptVersion = '3.2.2';
export const rxjsVersion = '6.3.3'; export const rxjsVersion = '6.3.3';
export const jestVersion = '24.1.0';
export const jestTypesVersion = '24.0.9';
export const jestPresetAngularVersion = '7.0.0';
export const tsJestversion = '24.0.0';
export const jasmineMarblesVersion = '^0.4.0'; export const jasmineMarblesVersion = '^0.4.0';
export const cypressVersion = '3.1.0'; export const cypressVersion = '3.1.0';

View File

@ -17,34 +17,36 @@ import { sortAlphabeticallyFunction } from './utils';
* parsable in order to be used in a rendering process using template. This * parsable in order to be used in a rendering process using template. This
* in order to generate a markdown file for each available schematic. * in order to generate a markdown file for each available schematic.
*/ */
const buildersSourceDirectory = path.join( interface DocConfig {
__dirname, source: string;
'../../packages/builders/src' output: string;
); }
const buildersOutputDirectory = path.join(__dirname, '../../docs/api-builders'); const buildersConfig = {
const builderCollectionFile = path.join( source: path.join(__dirname, '../../packages/builders/src'),
buildersSourceDirectory, output: path.join(__dirname, '../../docs/api-builders')
'builders.json' };
); const jestConfig = {
fs.removeSync(buildersOutputDirectory); source: path.join(__dirname, '../../packages/jest'),
const builderCollection = fs.readJsonSync(builderCollectionFile).builders; output: path.join(__dirname, '../../docs/api-jest/builders')
};
const docConfigs: DocConfig[] = [buildersConfig, jestConfig];
const registry = new CoreSchemaRegistry(); const registry = new CoreSchemaRegistry();
registry.addFormat(pathFormat); registry.addFormat(pathFormat);
registry.addFormat(htmlSelectorFormat); registry.addFormat(htmlSelectorFormat);
function generateSchematicList( function generateSchematicList(
builderCollection: Schematic, config: DocConfig,
registry: CoreSchemaRegistry registry: CoreSchemaRegistry
): Promise<Schematic>[] { ): Promise<Schematic>[] {
const builderCollectionFile = path.join(config.source, 'builders.json');
fs.removeSync(config.output);
const builderCollection = fs.readJsonSync(builderCollectionFile).builders;
return Object.keys(builderCollection).map(builderName => { return Object.keys(builderCollection).map(builderName => {
const builder = { const builder = {
name: builderName, name: builderName,
...builderCollection[builderName], ...builderCollection[builderName],
rawSchema: fs.readJsonSync( rawSchema: fs.readJsonSync(
path.join( path.join(config.source, builderCollection[builderName]['schema'])
buildersSourceDirectory,
builderCollection[builderName]['schema']
)
) )
}; };
@ -105,10 +107,19 @@ function generateFile(
); );
} }
Promise.all(generateSchematicList(builderCollection, registry)) Promise.all(
.then(builderList => builderList.map(generateTemplate)) docConfigs.map(config => {
.then(markdownList => Promise.all(generateSchematicList(config, registry))
markdownList.forEach(template => .then(builderList => builderList.map(generateTemplate))
generateFile(buildersOutputDirectory, template) .then(markdownList =>
) markdownList.forEach(template => generateFile(config.output, template))
); )
.then(() =>
console.log(
`Generated documentation for ${config.source} to ${config.output}`
)
);
})
).then(() => {
console.log('Done generating Builders Documentation');
});

View File

@ -26,11 +26,15 @@ const reactConfig = {
source: path.join(__dirname, '../../packages/react'), source: path.join(__dirname, '../../packages/react'),
output: path.join(__dirname, '../../docs/api-react') output: path.join(__dirname, '../../docs/api-react')
}; };
const jestConfig = {
source: path.join(__dirname, '../../packages/jest'),
output: path.join(__dirname, '../../docs/api-jest/schematics')
};
interface DocConfig { interface DocConfig {
source: string; source: string;
output: string; output: string;
} }
const docSections: DocConfig[] = [schematicsConfig, reactConfig]; const docSections: DocConfig[] = [schematicsConfig, reactConfig, jestConfig];
const registry = new CoreSchemaRegistry(); const registry = new CoreSchemaRegistry();
registry.addFormat(pathFormat); registry.addFormat(pathFormat);
registry.addFormat(htmlSelectorFormat); registry.addFormat(htmlSelectorFormat);

View File

@ -147,7 +147,9 @@ const options = {
'build/npm/builders/package.json', 'build/npm/builders/package.json',
'build/npm/nx/package.json', 'build/npm/nx/package.json',
'build/npm/schematics/package.json', 'build/npm/schematics/package.json',
'build/npm/create-nx-workspace/package.json' 'build/npm/create-nx-workspace/package.json',
'build/npm/jest/package.json',
'build/npm/react/package.json'
], ],
increment: parsedVersion.version, increment: parsedVersion.version,
requireUpstream: false, requireUpstream: false,

View File

@ -6,6 +6,10 @@
NX_VERSION=$1 NX_VERSION=$1
ANGULAR_CLI_VERSION=$2 ANGULAR_CLI_VERSION=$2
if [[ $NX_VERSION == "--local" ]]; then
NX_VERSION="*"
fi
./scripts/build.sh ./scripts/build.sh
cd build/packages cd build/packages
@ -13,9 +17,8 @@ cd build/packages
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i "" "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" schematics/src/lib-versions.js sed -i "" "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" schematics/src/lib-versions.js
sed -i "" "s|exports.schematicsVersion = '\*';|exports.schematicsVersion = '$NX_VERSION';|g" schematics/src/lib-versions.js sed -i "" "s|exports.schematicsVersion = '\*';|exports.schematicsVersion = '$NX_VERSION';|g" schematics/src/lib-versions.js
sed -i "" "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" react/src/utils/versions.js sed -i "" "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,jest}/src/utils/versions.js
sed -i "" "s|\*|$NX_VERSION|g" react/package.json sed -i "" "s|\*|$NX_VERSION|g" {schematics,react,jest}/package.json
sed -i "" "s|\*|$NX_VERSION|g" schematics/package.json
sed -i "" "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "" "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "" "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "" "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "" "s|NX_VERSION|$NX_VERSION|g" schematics/bin/create-nx-workspace.js sed -i "" "s|NX_VERSION|$NX_VERSION|g" schematics/bin/create-nx-workspace.js
@ -23,15 +26,21 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
else else
sed -i "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" schematics/src/lib-versions.js sed -i "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" schematics/src/lib-versions.js
sed -i "s|exports.schematicsVersion = '\*';|exports.schematicsVersion = '$NX_VERSION';|g" schematics/src/lib-versions.js sed -i "s|exports.schematicsVersion = '\*';|exports.schematicsVersion = '$NX_VERSION';|g" schematics/src/lib-versions.js
sed -i "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" react/src/utils/versions.js sed -i "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,jest}/src/utils/versions.js
sed -i "s|\*|$NX_VERSION|g" react/package.json sed -i "s|\*|$NX_VERSION|g" {schematics,react,jest}/package.json
sed -i "s|\*|$NX_VERSION|g" schematics/package.json
sed -i "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "s|NX_VERSION|$NX_VERSION|g" schematics/bin/create-nx-workspace.js sed -i "s|NX_VERSION|$NX_VERSION|g" schematics/bin/create-nx-workspace.js
sed -i "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" schematics/bin/create-nx-workspace.js sed -i "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" schematics/bin/create-nx-workspace.js
fi fi
if [[ $NX_VERSION == "*" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -E -i "" "s/\"@nrwl\/([^\"]+)\": \"\\*\"/\"@nrwl\/\1\": \"file:..\/\1\"/" {schematics,jest,react}/package.json
else
sed -E -i "s/\"@nrwl\/([^\"]+)\": \"\\*\"/\"@nrwl\/\1\": \"file:..\/\1\"/" {schematics,jest,react}/package.json
fi
fi
tar -czf nx.tgz nx tar -czf nx.tgz nx
tar -czf schematics.tgz schematics tar -czf schematics.tgz schematics

View File

@ -3,5 +3,5 @@
if [ -n "$1" ]; then if [ -n "$1" ]; then
jest --maxWorkers=1 ./build/packages/$1.spec.js jest --maxWorkers=1 ./build/packages/$1.spec.js
else else
jest --maxWorkers=1 ./build/packages/{schematics,bazel,builders,react} jest --maxWorkers=1 ./build/packages/{schematics,bazel,builders,jest,react}
fi fi