ts-node-builder
Version:
62 lines (49 loc) • 2.44 kB
text/typescript
import { Architect } from '@angular-devkit/architect';
import { TestingArchitectHost } from '@angular-devkit/architect/testing';
import { logging, schema } from '@angular-devkit/core';
import { Options } from './index';
const { join } = require('path');
describe('Command Runner Builder', () => {
let architect: Architect;
let architectHost: TestingArchitectHost;
beforeEach(async () => {
const registry = new schema.CoreSchemaRegistry();
registry.addPostTransform(schema.transforms.addUndefinedDefaults);
// Arguments to TestingArchitectHost are workspace and current directories.
// Since we don't use those, both are the same in this case.
architectHost = new TestingArchitectHost(__dirname, __dirname);
architect = new Architect(architectHost, registry);
// This will either take a Node package name, or a path to the directory
// for the package.json file.
await architectHost.addBuilderFromPackage(join(__dirname, '..'));
console.log('#', Array.from((architectHost as any)._builderMap.keys()));
jasmine.DEFAULT_TIMEOUT_INTERVAL = (1000 * 60) * 2; // 1 min
});
it('The dev server starts successfully', async () => {
// Create a logger that keeps an array of all messages that were logged.
const logger = new logging.Logger('');
const logs: string[] = [];
logger.subscribe(ev => logs.push(ev.message));
let options: Options = {
mainInOutput: 'testapp/test.ts',
NODE_ENV: 'development',
tsconfig: 'testapp/tsconfig.json',
watch: ['testapp'],
debug: false,
debugPort: 9229,
delayBetweenRestarts: 1.5,
copy: [
{ from: './dev/testapp/', to: './testos/' }
]
};
// A "run" can contain multiple outputs, and contains progress information.
const run = await architect.scheduleBuilder('ts-node-builder:dev', options, { logger }); // We pass the logger for checking later.
// The "result" member is the next output of the runner.
// This is of type BuilderOutput.
await run.result;
// Stop the builder from running. This really stops Architect from keeping
// the builder associated states in memory, since builders keep waiting
// to be scheduled.
await run.stop();
});
});