forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-module-engine-host_spec.ts
52 lines (44 loc) · 1.7 KB
/
node-module-engine-host_spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';
import { SchematicEngine } from '../index';
import { NodeModulesEngineHost } from './node-module-engine-host';
const TMP_DIR = process.env['TEST_TMPDIR'] || os.tmpdir();
describe('NodeModulesEngineHost', () => {
let tmpDir!: string;
beforeEach(() => {
tmpDir = fs.mkdtempSync(
path.join(TMP_DIR, 'angular-devkit-schematics-tools-node-module-engine-host'),
);
});
/** Creates a fake NPM module that can be used to test the node module engine host. */
function createFakeNpmModule() {
fs.mkdirSync(path.join(tmpDir, 'node_modules'));
fs.mkdirSync(path.join(tmpDir, 'node_modules/@angular/'));
fs.mkdirSync(path.join(tmpDir, 'node_modules/@angular/core'));
fs.mkdirSync(path.join(tmpDir, 'node_modules/@angular/core/schematics'));
fs.writeFileSync(
path.join(tmpDir, 'node_modules/@angular/core/package.json'),
JSON.stringify({ name: '@angular/core' }),
);
fs.writeFileSync(
path.join(tmpDir, 'node_modules/@angular/core/schematics/migrations.json'),
JSON.stringify({ schematics: {} }),
);
}
it('should properly create collections with explicit collection path', () => {
createFakeNpmModule();
const engineHost = new NodeModulesEngineHost([tmpDir]);
const engine = new SchematicEngine(engineHost);
expect(() => {
engine.createCollection(path.join('@angular/core', './schematics/migrations.json'));
}).not.toThrow();
});
});