|
| 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 | +// tslint:disable:no-implicit-dependencies |
| 10 | + |
| 11 | +import { SchematicEngine } from '@angular-devkit/schematics'; |
| 12 | +import * as fs from 'fs'; |
| 13 | +import * as os from 'os'; |
| 14 | +import * as path from 'path'; |
| 15 | +import { NodeModulesEngineHost } from './node-module-engine-host'; |
| 16 | + |
| 17 | +const TMP_DIR = process.env['$TEST_TMPDIR'] || os.tmpdir(); |
| 18 | + |
| 19 | +describe('NodeModulesEngineHost', () => { |
| 20 | + let tmpDir!: string; |
| 21 | + let previousDir!: string; |
| 22 | + |
| 23 | + beforeEach(() => { |
| 24 | + tmpDir = fs.mkdtempSync(path.join(TMP_DIR, |
| 25 | + 'angular-devkit-schematics-tools-node-module-engine-host')); |
| 26 | + previousDir = process.cwd(); |
| 27 | + process.chdir(tmpDir); |
| 28 | + }); |
| 29 | + |
| 30 | + afterEach(() => process.chdir(previousDir)); |
| 31 | + |
| 32 | + /** Creates a fake NPM module that can be used to test the node module engine host. */ |
| 33 | + function createFakeNpmModule() { |
| 34 | + fs.mkdirSync(path.join(tmpDir, 'node_modules')); |
| 35 | + fs.mkdirSync(path.join(tmpDir, 'node_modules/@angular/')); |
| 36 | + fs.mkdirSync(path.join(tmpDir, 'node_modules/@angular/core')); |
| 37 | + fs.mkdirSync(path.join(tmpDir, 'node_modules/@angular/core/schematics')); |
| 38 | + fs.writeFileSync(path.join(tmpDir, 'node_modules/@angular/core/package.json'), |
| 39 | + JSON.stringify({name: '@angular/core'})); |
| 40 | + fs.writeFileSync(path.join(tmpDir, 'node_modules/@angular/core/schematics/migrations.json'), |
| 41 | + JSON.stringify({schematics: {}})); |
| 42 | + } |
| 43 | + |
| 44 | + it('should properly create collections with explicit collection path', () => { |
| 45 | + createFakeNpmModule(); |
| 46 | + |
| 47 | + const engineHost = new NodeModulesEngineHost(); |
| 48 | + const engine = new SchematicEngine(engineHost); |
| 49 | + |
| 50 | + expect(() => { |
| 51 | + engine.createCollection(path.join('@angular/core', './schematics/migrations.json')); |
| 52 | + }).not.toThrow(); |
| 53 | + }); |
| 54 | +}); |
0 commit comments