Skip to content

Commit

Permalink
fix(angular): fix --skipFormat option on application schematic
Browse files Browse the repository at this point in the history
  • Loading branch information
philipjfulcher authored and vsavkin committed Feb 22, 2021
1 parent 35049dc commit 1681257
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 23 deletions.
68 changes: 46 additions & 22 deletions packages/angular/src/schematics/application/application.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Tree } from '@angular-devkit/schematics';
import { NxJson, readJsonInTree, updateJsonInTree } from '@nrwl/workspace';
import { createEmptyWorkspace, getFileContent } from '@nrwl/workspace/testing';
import * as stripJsonComments from 'strip-json-comments';
import { readJsonInTree, updateJsonInTree, NxJson } from '@nrwl/workspace';
import { runSchematic, callRule } from '../../utils/testing';
import { callRule, runSchematic } from '../../utils/testing';

const prettier = require('prettier');

describe('app', () => {
let appTree: Tree;
Expand Down Expand Up @@ -316,6 +318,28 @@ describe('app', () => {
});
});

describe('--skipFormat', () => {
it('should format files by default', async () => {
const spy = spyOn(prettier, 'getFileInfo').and.callThrough();

appTree = await runSchematic('app', { name: 'myApp' }, appTree);

expect(spy).toHaveBeenCalled();
});

it('should skip format when set to true', async () => {
const spy = spyOn(prettier, 'format').and.callThrough();

appTree = await runSchematic(
'app',
{ name: 'myApp', skipFormat: true },
appTree
);

expect(spy).not.toHaveBeenCalled();
});
});

describe('--linter', () => {
describe('eslint', () => {
it('should add an architect target for lint', async () => {
Expand Down Expand Up @@ -405,17 +429,18 @@ describe('app', () => {
]
`);
});
});

describe('tslint', () => {
it('should add an architect target for lint', async () => {
const tree = await runSchematic(
'app',
{ name: 'myApp', linter: 'tslint' },
appTree
);
const workspaceJson = readJsonInTree(tree, 'workspace.json');
expect(workspaceJson.projects['my-app'].architect.lint)
.toMatchInlineSnapshot(`
describe('tslint', () => {
it('should add an architect target for lint', async () => {
const tree = await runSchematic(
'app',
{ name: 'myApp', linter: 'tslint' },
appTree
);
const workspaceJson = readJsonInTree(tree, 'workspace.json');
expect(workspaceJson.projects['my-app'].architect.lint)
.toMatchInlineSnapshot(`
Object {
"builder": "@angular-devkit/build-angular:tslint",
"options": Object {
Expand All @@ -431,17 +456,17 @@ describe('app', () => {
},
}
`);
});
});

it('should add valid tslint JSON configuration', async () => {
const tree = await runSchematic(
'app',
{ name: 'myApp', linter: 'tslint' },
appTree
);
it('should add valid tslint JSON configuration', async () => {
const tree = await runSchematic(
'app',
{ name: 'myApp', linter: 'tslint' },
appTree
);

const tslintConfig = readJsonInTree(tree, 'apps/my-app/tslint.json');
expect(tslintConfig).toMatchInlineSnapshot(`
const tslintConfig = readJsonInTree(tree, 'apps/my-app/tslint.json');
expect(tslintConfig).toMatchInlineSnapshot(`
Object {
"extends": "../../tslint.json",
"linterOptions": Object {
Expand All @@ -465,7 +490,6 @@ describe('app', () => {
},
}
`);
});
});
});
});
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/src/schematics/application/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ export default function (schema: Schema): Rule {
supportTsx: false,
skipSerializers: false,
setupFile: 'angular',
skipFormat: options.skipFormat,
})
: noop(),
options.unitTestRunner === 'karma'
Expand All @@ -848,6 +849,7 @@ export default function (schema: Schema): Rule {
directory: options.directory,
project: options.name,
linter: options.linter,
skipFormat: options.skipFormat,
})
: noop(),
addEditorTsConfigReference(options),
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/schematics/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,6 @@ export default function (options: Schema): Rule {
updateDependencies(options),
addUnitTestRunner(options),
addE2eTestRunner(options),
formatFiles(),
formatFiles(options),
]);
}

0 comments on commit 1681257

Please sign in to comment.