|
1 | | -import { Tree } from '@angular-devkit/schematics'; |
2 | | -import { SchematicTestRunner } from '@angular-devkit/schematics/testing'; |
3 | | -import * as path from 'path'; |
| 1 | +import { Architect } from '@angular-devkit/architect'; |
| 2 | +import { TestingArchitectHost } from '@angular-devkit/architect/testing'; |
| 3 | +import { logging, schema } from '@angular-devkit/core'; |
| 4 | +const { join } = require('path'); |
4 | 5 |
|
| 6 | +describe('svg-icons-builder', () => { |
| 7 | + let architect: Architect; |
| 8 | + let architectHost: TestingArchitectHost; |
5 | 9 |
|
6 | | -const collectionPath = path.join(__dirname, '../collection.json'); |
| 10 | + beforeEach(async () => { |
| 11 | + const registry = new schema.CoreSchemaRegistry(); |
| 12 | + registry.addPostTransform(schema.transforms.addUndefinedDefaults); |
| 13 | + const workspaceRoot = join(__dirname, '..', '..'); |
7 | 14 |
|
| 15 | + // TestingArchitectHost() takes workspace and current directories. |
| 16 | + // Since we don't use those, both are the same in this case. |
| 17 | + architectHost = new TestingArchitectHost(__dirname, __dirname); |
| 18 | + architect = new Architect(architectHost, registry); |
| 19 | + |
| 20 | + // This will either take a Node package name, or a path to the directory |
| 21 | + // for the package.json file. |
| 22 | + await architectHost.addBuilderFromPackage(workspaceRoot); |
| 23 | + console.log('#', Array.from((architectHost as any)._builderMap.keys())) |
| 24 | + }); |
8 | 25 |
|
9 | | -describe('svg-icons-builder', () => { |
10 | 26 | it('works', async () => { |
11 | | - const runner = new SchematicTestRunner('schematics', collectionPath); |
12 | | - const tree = await runner.runSchematicAsync('svg-icons-builder', {}, Tree.empty()).toPromise(); |
| 27 | + const logger = new logging.Logger(''); |
| 28 | + const logs: string[] = []; |
| 29 | + logger.subscribe(ev => logs.push(ev.message)); |
| 30 | + |
| 31 | + // A "run" can have multiple outputs, and contains progress information. |
| 32 | + const run = await architect.scheduleBuilder('@angular-extensions/svg-icons-builder:svg-icons-builder', { |
| 33 | + command: 'node', |
| 34 | + args: ['--print', '\'foo\''], |
| 35 | + }, { logger }); // We pass the logger for checking later. |
| 36 | + |
| 37 | + // The "result" member (of type BuilderOutput) is the next output. |
| 38 | + await run.result; |
| 39 | + |
| 40 | + // Stop the builder from running. This stops Architect from keeping |
| 41 | + // the builder-associated states in memory, since builders keep waiting |
| 42 | + // to be scheduled. |
| 43 | + await run.stop(); |
13 | 44 |
|
14 | | - expect(tree.files).toEqual([]); |
| 45 | + // Expect that foo was logged |
| 46 | + expect(logs).toContain('foo'); |
15 | 47 | }); |
16 | 48 | }); |
0 commit comments