Skip to content

Commit 1a61fe0

Browse files
committed
fixup! fix(@angular/cli): ng-update migrations not running with --migrate-only
Add tests
1 parent 9230362 commit 1a61fe0

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import { SchematicEngine } from '@angular-devkit/schematics';
10+
import * as path from 'path';
11+
import * as fs from 'fs';
12+
import * as os from 'os';
13+
14+
import { NodeModulesEngineHost } from './node-module-engine-host';
15+
16+
const TMP_DIR = process.env['$TEST_TMPDIR'] || os.tmpdir();
17+
18+
describe('NodeModulesEngineHost', () => {
19+
let tmpDir: string|null = null;
20+
let previousDir: string|null = null;
21+
22+
beforeEach(() => {
23+
tmpDir = fs.mkdtempSync(path.join(TMP_DIR, 'angular-devkit-schematics-tools-node-module-engine-host'));
24+
previousDir = process.cwd();
25+
process.chdir(tmpDir!);
26+
});
27+
28+
afterEach(() => process.chdir(previousDir!));
29+
30+
/** Creates a fake NPM module that can be used to test the node module engine host. */
31+
function createFakeNpmModule() {
32+
fs.mkdirSync(path.join(tmpDir!, 'node_modules'));
33+
fs.mkdirSync(path.join(tmpDir!, 'node_modules/@angular/'));
34+
fs.mkdirSync(path.join(tmpDir!, 'node_modules/@angular/core'));
35+
fs.mkdirSync(path.join(tmpDir!, 'node_modules/@angular/core/schematics'));
36+
fs.writeFileSync(path.join(tmpDir!, 'node_modules/@angular/core/package.json'), JSON.stringify({name: "@angular/core"}));
37+
fs.writeFileSync(path.join(tmpDir!, 'node_modules/@angular/core/schematics/migrations.json'), JSON.stringify({schematics: {}}));
38+
}
39+
40+
it('should properly create collections with explicit collection path', () => {
41+
createFakeNpmModule();
42+
43+
const engineHost = new NodeModulesEngineHost();
44+
const engine = new SchematicEngine(engineHost);
45+
46+
expect(() => engine.createCollection(path.join('@angular/core', './schematics/migrations.json'))).not.toThrow();
47+
});
48+
});

0 commit comments

Comments
 (0)