refactor(testing): separate jest to @nrwl/jest
This commit is contained in:
parent
9ee487d20f
commit
625b2837a8
@ -4,6 +4,8 @@ tmp
|
||||
node_modules
|
||||
/package.json
|
||||
packages/schematics/src/collection/**/files/**/*.json
|
||||
packages/react/src/schematics/**/files/**/*.json
|
||||
packages/jest/src/schematics/**/files/**/*.json
|
||||
/.vscode
|
||||
/.idea
|
||||
/.github
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# jest-project [hidden]
|
||||
# jest-project
|
||||
|
||||
Add Jest configuration to a project
|
||||
|
||||
@ -19,7 +19,7 @@ The name of the project.
|
||||
|
||||
### setupFile
|
||||
|
||||
Default: `angular`
|
||||
Default: `none`
|
||||
|
||||
Type: `string`
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
# jest [hidden]
|
||||
# ng-add [hidden]
|
||||
|
||||
Add Jest configuration to the workspace
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
ng generate jest ...
|
||||
ng generate ng-add ...
|
||||
|
||||
```
|
||||
@ -1,39 +1,23 @@
|
||||
import {
|
||||
newProject,
|
||||
runCLI,
|
||||
newLib,
|
||||
runCLIAsync,
|
||||
newApp,
|
||||
copyMissingPackages,
|
||||
ensureProject,
|
||||
uniq
|
||||
} from '../utils';
|
||||
import { newLib, runCLIAsync, newApp, ensureProject, uniq } from '../utils';
|
||||
|
||||
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();
|
||||
const mylib = uniq('mylib');
|
||||
const myapp = uniq('myapp');
|
||||
newApp(`${myapp} --unit-test-runner jest --framework=angular`);
|
||||
newLib(`${mylib} --unit-test-runner jest --framework=angular`);
|
||||
|
||||
await Promise.all([
|
||||
runCLIAsync(`generate service test --project ${myapp}`),
|
||||
runCLIAsync(`generate component test --project ${myapp}`),
|
||||
runCLIAsync(`generate service test --project ${mylib}`),
|
||||
runCLIAsync(`generate component test --project ${mylib}`)
|
||||
]);
|
||||
const jestResult = await runCLIAsync(`test ${mylib}`);
|
||||
expect(jestResult.stderr).toContain('Test Suites: 3 passed, 3 total');
|
||||
const appResult = await runCLIAsync(`test ${myapp}`);
|
||||
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();
|
||||
}, 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);
|
||||
});
|
||||
|
||||
@ -1,14 +1,9 @@
|
||||
import {
|
||||
newApp,
|
||||
newLib,
|
||||
newProject,
|
||||
readJson,
|
||||
runCLI,
|
||||
updateFile,
|
||||
exists,
|
||||
runNgNew,
|
||||
cleanup,
|
||||
copyMissingPackages,
|
||||
getSize,
|
||||
expectTestsPass,
|
||||
runCLIAsync,
|
||||
@ -19,8 +14,11 @@ import {
|
||||
import { toClassName } from '@nrwl/schematics/src/utils/name-utils';
|
||||
|
||||
describe('Nrwl Workspace', () => {
|
||||
it('should work', async () => {
|
||||
beforeEach(() => {
|
||||
ensureProject();
|
||||
});
|
||||
|
||||
it('should work', async () => {
|
||||
const myapp = uniq('myapp');
|
||||
const mylib = uniq('mylib');
|
||||
newApp(`${myapp} --directory=myDir`);
|
||||
@ -73,7 +71,6 @@ describe('Nrwl Workspace', () => {
|
||||
}, 1000000);
|
||||
|
||||
it('should support router config generation (lazy)', async () => {
|
||||
ensureProject();
|
||||
const myapp = uniq('myapp');
|
||||
const mylib = uniq('mylib');
|
||||
newApp(`${myapp} --directory=myDir --routing`);
|
||||
@ -88,7 +85,6 @@ describe('Nrwl Workspace', () => {
|
||||
}, 1000000);
|
||||
|
||||
it('should support router config generation (eager)', async () => {
|
||||
ensureProject();
|
||||
const myapp = uniq('myapp');
|
||||
newApp(`${myapp} --directory=myDir --routing`);
|
||||
const mylib = uniq('mylib');
|
||||
|
||||
@ -25,6 +25,8 @@ export function newProject(): void {
|
||||
if (!directoryExists('./tmp/proj_backup')) {
|
||||
runNgNew('--collection=@nrwl/schematics --npmScope=proj', true);
|
||||
copyMissingPackages();
|
||||
runCLI('add @nrwl/jest');
|
||||
runCLI('add @nrwl/react');
|
||||
execSync('mv ./tmp/proj ./tmp/proj_backup');
|
||||
}
|
||||
execSync('cp -a ./tmp/proj_backup ./tmp/proj');
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "./scripts/build.sh",
|
||||
"build": "./scripts/package.sh --local",
|
||||
"commit": "git-cz",
|
||||
"checkcommit": "node ./scripts/commit-lint.js",
|
||||
"e2e": "./scripts/e2e.sh",
|
||||
|
||||
@ -21,11 +21,6 @@
|
||||
"schema": "./web/dev-server/schema.json",
|
||||
"description": "Serve a web application"
|
||||
},
|
||||
"jest": {
|
||||
"class": "./jest/jest.builder",
|
||||
"schema": "./jest/schema.json",
|
||||
"description": "Run Jest unit tests"
|
||||
},
|
||||
"cypress": {
|
||||
"class": "./cypress/cypress.builder",
|
||||
"schema": "./cypress/schema.json",
|
||||
|
||||
10
packages/jest/builders.json
Normal file
10
packages/jest/builders.json
Normal 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
17
packages/jest/collection.json
Normal file
17
packages/jest/collection.json
Normal 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
0
packages/jest/index.ts
Normal file
3
packages/jest/migrations.json
Normal file
3
packages/jest/migrations.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"schematics": {}
|
||||
}
|
||||
41
packages/jest/package.json
Normal file
41
packages/jest/package.json
Normal 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"
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"title": "Jest Target",
|
||||
"title": "Jest Builder",
|
||||
"description": "Jest target options for Build Facade",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@ -1,6 +1,7 @@
|
||||
import { Tree, VirtualTree } from '@angular-devkit/schematics';
|
||||
import { createEmptyWorkspace, runSchematic } from '../../utils/testing-utils';
|
||||
import { readJsonInTree } from '@nrwl/schematics/src/utils/ast-utils';
|
||||
import { createEmptyWorkspace } from '@nrwl/schematics/testing';
|
||||
import { readJsonInTree, updateJsonInTree } from '@nrwl/schematics';
|
||||
import { runSchematic, callRule } from '../../utils/testing';
|
||||
|
||||
describe('jestProject', () => {
|
||||
let appTree: Tree;
|
||||
@ -8,12 +9,31 @@ describe('jestProject', () => {
|
||||
beforeEach(async () => {
|
||||
appTree = new VirtualTree();
|
||||
appTree = createEmptyWorkspace(appTree);
|
||||
appTree = await runSchematic(
|
||||
'lib',
|
||||
{
|
||||
name: 'lib1',
|
||||
unitTestRunner: 'none'
|
||||
},
|
||||
appTree = await callRule(
|
||||
updateJsonInTree('angular.json', json => {
|
||||
json.projects.lib1 = {
|
||||
root: 'libs/lib1',
|
||||
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
|
||||
);
|
||||
});
|
||||
@ -22,7 +42,8 @@ describe('jestProject', () => {
|
||||
const resultTree = await runSchematic(
|
||||
'jest-project',
|
||||
{
|
||||
project: 'lib1'
|
||||
project: 'lib1',
|
||||
setupFile: 'angular'
|
||||
},
|
||||
appTree
|
||||
);
|
||||
@ -35,13 +56,14 @@ describe('jestProject', () => {
|
||||
const resultTree = await runSchematic(
|
||||
'jest-project',
|
||||
{
|
||||
project: 'lib1'
|
||||
project: 'lib1',
|
||||
setupFile: 'angular'
|
||||
},
|
||||
appTree
|
||||
);
|
||||
const angularJson = readJsonInTree(resultTree, 'angular.json');
|
||||
expect(angularJson.projects.lib1.architect.test).toEqual({
|
||||
builder: '@nrwl/builders:jest',
|
||||
builder: '@nrwl/jest:jest',
|
||||
options: {
|
||||
jestConfig: 'libs/lib1/jest.config.js',
|
||||
setupFile: 'libs/lib1/src/test-setup.ts',
|
||||
@ -91,7 +113,8 @@ describe('jestProject', () => {
|
||||
const resultTree = await runSchematic(
|
||||
'jest-project',
|
||||
{
|
||||
project: 'lib1'
|
||||
project: 'lib1',
|
||||
setupFile: 'angular'
|
||||
},
|
||||
appTree
|
||||
);
|
||||
@ -168,21 +191,6 @@ describe('jestProject', () => {
|
||||
).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', () => {
|
||||
@ -9,18 +9,16 @@ import {
|
||||
move,
|
||||
template,
|
||||
noop,
|
||||
filter,
|
||||
schematic
|
||||
filter
|
||||
} from '@angular-devkit/schematics';
|
||||
import { readJsonInTree, updateJsonInTree } from '@nrwl/schematics';
|
||||
import {
|
||||
getProjectConfig,
|
||||
readJsonInTree,
|
||||
updateJsonInTree,
|
||||
addDepsToPackageJson
|
||||
} from '../../utils/ast-utils';
|
||||
import { offsetFromRoot } from '../../utils/common';
|
||||
} from '@nrwl/schematics/src/utils/ast-utils';
|
||||
import { offsetFromRoot } from '@nrwl/schematics/src/utils/common';
|
||||
import { join, normalize } from '@angular-devkit/core';
|
||||
import { jestPresetAngularVersion, tsJestversion } from '../../lib-versions';
|
||||
import { jestPresetAngularVersion } from '../../utils/versions';
|
||||
|
||||
export interface JestProjectSchema {
|
||||
project: string;
|
||||
@ -51,8 +49,16 @@ function generateFiles(options: JestProjectSchema): Rule {
|
||||
}
|
||||
|
||||
function updateTsConfig(options: JestProjectSchema): Rule {
|
||||
return (host: Tree, context: SchematicContext) => {
|
||||
return (host: Tree) => {
|
||||
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 {
|
||||
...json,
|
||||
@ -71,7 +77,7 @@ function updateAngularJson(options: JestProjectSchema): Rule {
|
||||
return updateJsonInTree('angular.json', json => {
|
||||
const projectConfig = json.projects[options.project];
|
||||
projectConfig.architect.test = {
|
||||
builder: '@nrwl/builders:jest',
|
||||
builder: '@nrwl/jest:jest',
|
||||
options: {
|
||||
jestConfig: join(normalize(projectConfig.root), 'jest.config.js'),
|
||||
tsConfig: join(normalize(projectConfig.root), 'tsconfig.spec.json')
|
||||
@ -97,8 +103,6 @@ function addDependencies(options: JestProjectSchema): Rule {
|
||||
const devDeps = {};
|
||||
if (options.setupFile === 'angular') {
|
||||
devDeps['jest-preset-angular'] = jestPresetAngularVersion;
|
||||
} else {
|
||||
devDeps['ts-jest'] = tsJestversion;
|
||||
}
|
||||
return addDepsToPackageJson({}, devDeps);
|
||||
}
|
||||
@ -113,8 +117,10 @@ function check(options: JestProjectSchema): Rule {
|
||||
}
|
||||
const packageJson = readJsonInTree(host, 'package.json');
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/schema",
|
||||
"id": "SchematicsNxJestProject",
|
||||
"title": "Create Jest Configuration for a project",
|
||||
"id": "NxJestProject",
|
||||
"title": "Add Jest Configuration to a project",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"project": {
|
||||
@ -21,7 +21,7 @@
|
||||
"type": "string",
|
||||
"enum": ["none", "angular", "web-components"],
|
||||
"description": "The setup file to be generated",
|
||||
"default": "angular"
|
||||
"default": "none"
|
||||
},
|
||||
"skipSerializers": {
|
||||
"type": "boolean",
|
||||
@ -3,7 +3,7 @@ module.exports = {
|
||||
transform: {
|
||||
'^.+\\.(ts|js|html)$': 'ts-jest'
|
||||
},
|
||||
resolver: '@nrwl/builders/plugins/jest/resolver',
|
||||
resolver: '@nrwl/jest/plugins/resolver',
|
||||
moduleFileExtensions: ['ts', 'js', 'html'],
|
||||
collectCoverage: true,
|
||||
coverageReporters: ['html']
|
||||
@ -1,12 +1,7 @@
|
||||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
|
||||
import * as path from 'path';
|
||||
import { Tree, VirtualTree } from '@angular-devkit/schematics';
|
||||
import {
|
||||
createEmptyWorkspace,
|
||||
createLib,
|
||||
runSchematic
|
||||
} from '../../utils/testing-utils';
|
||||
import { createEmptyWorkspace } from '@nrwl/schematics/testing';
|
||||
import { readJsonInTree } from '@nrwl/schematics/src/utils/ast-utils';
|
||||
import { runSchematic } from '../../utils/testing';
|
||||
|
||||
describe('jest', () => {
|
||||
let appTree: Tree;
|
||||
@ -17,15 +12,16 @@ describe('jest', () => {
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
it('should add dependencies', async () => {
|
||||
const resultTree = await runSchematic('jest', {}, appTree);
|
||||
const resultTree = await runSchematic('ng-add', {}, appTree);
|
||||
const packageJson = readJsonInTree(resultTree, 'package.json');
|
||||
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['ts-jest']).toBeDefined();
|
||||
});
|
||||
});
|
||||
33
packages/jest/src/schematics/ng-add/ng-add.ts
Normal file
33
packages/jest/src/schematics/ng-add/ng-add.ts
Normal 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]);
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/schema",
|
||||
"id": "SchematicsNxJest",
|
||||
"title": "Create Jest Configuration for the workspace",
|
||||
"id": "NxJestNgAdd",
|
||||
"title": "Add Jest Configuration to a workspace",
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
"required": []
|
||||
16
packages/jest/src/utils/testing.ts
Normal file
16
packages/jest/src/utils/testing.ts
Normal 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();
|
||||
}
|
||||
5
packages/jest/src/utils/versions.ts
Normal file
5
packages/jest/src/utils/versions.ts
Normal 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';
|
||||
@ -32,6 +32,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@angular-devkit/core": "~7.3.1",
|
||||
"@angular-devkit/schematics": "~7.3.1"
|
||||
"@angular-devkit/schematics": "~7.3.1",
|
||||
"@nrwl/jest": "*"
|
||||
}
|
||||
}
|
||||
|
||||
@ -189,7 +189,7 @@ export default function(schema: Schema): Rule {
|
||||
})
|
||||
: noop(),
|
||||
options.unitTestRunner === 'jest'
|
||||
? externalSchematic('@nrwl/schematics', 'jest-project', {
|
||||
? externalSchematic('@nrwl/jest', 'jest-project', {
|
||||
project: options.name,
|
||||
supportTsx: true,
|
||||
skipSerializers: true,
|
||||
|
||||
@ -101,7 +101,7 @@ export default function(schema: Schema): Rule {
|
||||
addProject(options),
|
||||
updateNxJson(options),
|
||||
options.unitTestRunner !== 'none'
|
||||
? externalSchematic('@nrwl/schematics', 'jest-project', {
|
||||
? externalSchematic('@nrwl/jest', 'jest-project', {
|
||||
project: options.name,
|
||||
setupFile: 'none',
|
||||
supportTsx: true,
|
||||
|
||||
@ -1,7 +1,14 @@
|
||||
import { Rule, chain } from '@angular-devkit/schematics';
|
||||
import {
|
||||
Rule,
|
||||
chain,
|
||||
externalSchematic,
|
||||
noop,
|
||||
Tree
|
||||
} from '@angular-devkit/schematics';
|
||||
import {
|
||||
addDepsToPackageJson,
|
||||
updateJsonInTree
|
||||
updateJsonInTree,
|
||||
readJsonInTree
|
||||
} from '@nrwl/schematics/src/utils/ast-utils';
|
||||
import {
|
||||
frameworkVersion,
|
||||
@ -35,6 +42,22 @@ function moveDependency(): Rule {
|
||||
});
|
||||
}
|
||||
|
||||
export default function() {
|
||||
return chain([addDependencies(), moveDependency()]);
|
||||
function addJest(): Rule {
|
||||
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()]);
|
||||
}
|
||||
|
||||
@ -50,20 +50,6 @@
|
||||
"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": {
|
||||
"factory": "./collection/karma",
|
||||
"schema": "./collection/karma/schema.json",
|
||||
|
||||
@ -515,7 +515,7 @@ export default function(schema: Schema): Rule {
|
||||
updateDependencies(options),
|
||||
updateLinting(options),
|
||||
options.unitTestRunner === 'jest'
|
||||
? schematic('jest-project', {
|
||||
? externalSchematic('@nrwl/jest', 'jest-project', {
|
||||
project: options.name,
|
||||
supportTsx: false,
|
||||
skipSerializers: options.framework !== Framework.Angular,
|
||||
|
||||
@ -4,7 +4,5 @@
|
||||
"sourceMap": false,
|
||||
"outDir": "<%= offsetFromRoot %>dist/out-tsc/<%= projectRoot %>/src"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
]
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
|
||||
@ -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]);
|
||||
}
|
||||
@ -450,7 +450,7 @@ export default function(schema: Schema): Rule {
|
||||
updateProject(options),
|
||||
updateTsConfig(options),
|
||||
options.unitTestRunner === 'jest'
|
||||
? schematic('jest-project', {
|
||||
? externalSchematic('@nrwl/jest', 'jest-project', {
|
||||
project: options.name,
|
||||
setupFile:
|
||||
options.framework === Framework.Angular ? 'angular' : 'none',
|
||||
|
||||
@ -9,7 +9,8 @@ import {
|
||||
mergeWith,
|
||||
apply,
|
||||
url,
|
||||
template
|
||||
template,
|
||||
externalSchematic
|
||||
} from '@angular-devkit/schematics';
|
||||
import { join, normalize, Path } from '@angular-devkit/core';
|
||||
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
|
||||
@ -222,7 +223,7 @@ export default function(schema: Schema): Rule {
|
||||
updateNxJson(options),
|
||||
options.framework !== 'none' ? createSourceCode(options) : noop(),
|
||||
options.unitTestRunner === 'jest'
|
||||
? schematic('jest-project', {
|
||||
? externalSchematic('@nrwl/jest', 'jest-project', {
|
||||
project: options.name,
|
||||
setupFile: 'none',
|
||||
skipSerializers: true
|
||||
|
||||
@ -27,8 +27,7 @@
|
||||
"help": "./node_modules/.bin/nx help"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@angular/cli": "<%= angularCliVersion %>",
|
||||
"@nrwl/schematics": "<%= schematicsVersion %>",
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
{
|
||||
"rulesDirectory": [
|
||||
"node_modules/@nrwl/schematics/src/tslint"
|
||||
],
|
||||
"rulesDirectory": ["node_modules/@nrwl/schematics/src/tslint"],
|
||||
"rules": {
|
||||
"arrow-return-shorthand": true,
|
||||
"callable-types": true,
|
||||
@ -10,10 +8,7 @@
|
||||
"severity": "warn"
|
||||
},
|
||||
"forin": true,
|
||||
"import-blacklist": [
|
||||
true,
|
||||
"rxjs/Rx"
|
||||
],
|
||||
"import-blacklist": [true, "rxjs/Rx"],
|
||||
"interface-over-type-literal": true,
|
||||
"member-access": false,
|
||||
"member-ordering": [
|
||||
@ -29,24 +24,14 @@
|
||||
],
|
||||
"no-arg": true,
|
||||
"no-bitwise": true,
|
||||
"no-console": [
|
||||
true,
|
||||
"debug",
|
||||
"info",
|
||||
"time",
|
||||
"timeEnd",
|
||||
"trace"
|
||||
],
|
||||
"no-console": [true, "debug", "info", "time", "timeEnd", "trace"],
|
||||
"no-construct": true,
|
||||
"no-debugger": true,
|
||||
"no-duplicate-super": true,
|
||||
"no-empty": false,
|
||||
"no-empty-interface": true,
|
||||
"no-eval": true,
|
||||
"no-inferrable-types": [
|
||||
true,
|
||||
"ignore-params"
|
||||
],
|
||||
"no-inferrable-types": [true, "ignore-params"],
|
||||
"no-misused-new": true,
|
||||
"no-non-null-assertion": true,
|
||||
"no-shadowed-variable": true,
|
||||
@ -60,10 +45,7 @@
|
||||
"object-literal-sort-keys": false,
|
||||
"prefer-const": true,
|
||||
"radix": true,
|
||||
"triple-equals": [
|
||||
true,
|
||||
"allow-null-check"
|
||||
],
|
||||
"triple-equals": [true, "allow-null-check"],
|
||||
"unified-signatures": true,
|
||||
"variable-name": false,
|
||||
|
||||
|
||||
@ -10,10 +10,6 @@ export const latestMigration = '20180507-create-nx-json';
|
||||
export const prettierVersion = '1.16.4';
|
||||
export const typescriptVersion = '3.2.2';
|
||||
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 cypressVersion = '3.1.0';
|
||||
|
||||
|
||||
@ -17,34 +17,36 @@ import { sortAlphabeticallyFunction } from './utils';
|
||||
* parsable in order to be used in a rendering process using template. This
|
||||
* in order to generate a markdown file for each available schematic.
|
||||
*/
|
||||
const buildersSourceDirectory = path.join(
|
||||
__dirname,
|
||||
'../../packages/builders/src'
|
||||
);
|
||||
const buildersOutputDirectory = path.join(__dirname, '../../docs/api-builders');
|
||||
const builderCollectionFile = path.join(
|
||||
buildersSourceDirectory,
|
||||
'builders.json'
|
||||
);
|
||||
fs.removeSync(buildersOutputDirectory);
|
||||
const builderCollection = fs.readJsonSync(builderCollectionFile).builders;
|
||||
interface DocConfig {
|
||||
source: string;
|
||||
output: string;
|
||||
}
|
||||
const buildersConfig = {
|
||||
source: path.join(__dirname, '../../packages/builders/src'),
|
||||
output: path.join(__dirname, '../../docs/api-builders')
|
||||
};
|
||||
const jestConfig = {
|
||||
source: path.join(__dirname, '../../packages/jest'),
|
||||
output: path.join(__dirname, '../../docs/api-jest/builders')
|
||||
};
|
||||
const docConfigs: DocConfig[] = [buildersConfig, jestConfig];
|
||||
const registry = new CoreSchemaRegistry();
|
||||
registry.addFormat(pathFormat);
|
||||
registry.addFormat(htmlSelectorFormat);
|
||||
|
||||
function generateSchematicList(
|
||||
builderCollection: Schematic,
|
||||
config: DocConfig,
|
||||
registry: CoreSchemaRegistry
|
||||
): 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 => {
|
||||
const builder = {
|
||||
name: builderName,
|
||||
...builderCollection[builderName],
|
||||
rawSchema: fs.readJsonSync(
|
||||
path.join(
|
||||
buildersSourceDirectory,
|
||||
builderCollection[builderName]['schema']
|
||||
)
|
||||
path.join(config.source, builderCollection[builderName]['schema'])
|
||||
)
|
||||
};
|
||||
|
||||
@ -105,10 +107,19 @@ function generateFile(
|
||||
);
|
||||
}
|
||||
|
||||
Promise.all(generateSchematicList(builderCollection, registry))
|
||||
Promise.all(
|
||||
docConfigs.map(config => {
|
||||
Promise.all(generateSchematicList(config, registry))
|
||||
.then(builderList => builderList.map(generateTemplate))
|
||||
.then(markdownList =>
|
||||
markdownList.forEach(template =>
|
||||
generateFile(buildersOutputDirectory, template)
|
||||
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');
|
||||
});
|
||||
|
||||
@ -26,11 +26,15 @@ const reactConfig = {
|
||||
source: path.join(__dirname, '../../packages/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 {
|
||||
source: string;
|
||||
output: string;
|
||||
}
|
||||
const docSections: DocConfig[] = [schematicsConfig, reactConfig];
|
||||
const docSections: DocConfig[] = [schematicsConfig, reactConfig, jestConfig];
|
||||
const registry = new CoreSchemaRegistry();
|
||||
registry.addFormat(pathFormat);
|
||||
registry.addFormat(htmlSelectorFormat);
|
||||
|
||||
@ -147,7 +147,9 @@ const options = {
|
||||
'build/npm/builders/package.json',
|
||||
'build/npm/nx/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,
|
||||
requireUpstream: false,
|
||||
|
||||
@ -6,6 +6,10 @@
|
||||
NX_VERSION=$1
|
||||
ANGULAR_CLI_VERSION=$2
|
||||
|
||||
if [[ $NX_VERSION == "--local" ]]; then
|
||||
NX_VERSION="*"
|
||||
fi
|
||||
|
||||
./scripts/build.sh
|
||||
|
||||
cd build/packages
|
||||
@ -13,9 +17,8 @@ cd build/packages
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
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.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" react/src/utils/versions.js
|
||||
sed -i "" "s|\*|$NX_VERSION|g" react/package.json
|
||||
sed -i "" "s|\*|$NX_VERSION|g" schematics/package.json
|
||||
sed -i "" "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,jest}/src/utils/versions.js
|
||||
sed -i "" "s|\*|$NX_VERSION|g" {schematics,react,jest}/package.json
|
||||
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|NX_VERSION|$NX_VERSION|g" schematics/bin/create-nx-workspace.js
|
||||
@ -23,15 +26,21 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
else
|
||||
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.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" react/src/utils/versions.js
|
||||
sed -i "s|\*|$NX_VERSION|g" react/package.json
|
||||
sed -i "s|\*|$NX_VERSION|g" schematics/package.json
|
||||
sed -i "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,jest}/src/utils/versions.js
|
||||
sed -i "s|\*|$NX_VERSION|g" {schematics,react,jest}/package.json
|
||||
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|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
|
||||
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 schematics.tgz schematics
|
||||
|
||||
@ -3,5 +3,5 @@
|
||||
if [ -n "$1" ]; then
|
||||
jest --maxWorkers=1 ./build/packages/$1.spec.js
|
||||
else
|
||||
jest --maxWorkers=1 ./build/packages/{schematics,bazel,builders,react}
|
||||
jest --maxWorkers=1 ./build/packages/{schematics,bazel,builders,jest,react}
|
||||
fi
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user