本文整理汇总了TypeScript中@angular-devkit/architect.Architect类的典型用法代码示例。如果您正苦于以下问题:TypeScript Architect类的具体用法?TypeScript Architect怎么用?TypeScript Architect使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Architect类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('Browser Builder deploy url', () => {
const targetSpec = { project: 'app', target: 'build' };
let architect: Architect;
beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;
});
afterEach(async () => host.restore().toPromise());
it('uses deploy url for bundles urls and runtime', async () => {
const overrides = { deployUrl: 'deployUrl/' };
const overrides2 = { deployUrl: 'http://example.com/some/path/' };
const run = await architect.scheduleTarget(targetSpec, overrides);
const output = await run.result as BrowserBuilderOutput;
expect(output.success).toBe(true);
expect(output.outputPath).not.toBeUndefined();
const outputPath = normalize(output.outputPath);
const fileName = join(outputPath, 'index.html');
const runtimeFileName = join(outputPath, 'runtime.js');
const content = virtualFs.fileBufferToString(await host.read(normalize(fileName)).toPromise());
expect(content).toContain('deployUrl/main.js');
const runtimeContent = virtualFs.fileBufferToString(
await host.read(normalize(runtimeFileName)).toPromise(),
);
expect(runtimeContent).toContain('deployUrl/');
const run2 = await architect.scheduleTarget(targetSpec, overrides2);
const output2 = await run2.result as BrowserBuilderOutput;
expect(output2.outputPath).toEqual(outputPath); // These should be the same.
const content2 = virtualFs.fileBufferToString(await host.read(normalize(fileName)).toPromise());
expect(content2).toContain('http://example.com/some/path/main.js');
await run.stop();
await run2.stop();
});
});
示例2: describe
describe('Browser Builder output path', () => {
const target = { project: 'app', target: 'build' };
let architect: Architect;
beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;
});
afterEach(async () => host.restore().toPromise());
it('deletes output path', async () => {
// Write a file to the output path to later verify it was deleted.
await host.write(
join(host.root(), 'dist/file.txt'),
virtualFs.stringToFileBuffer('file'),
).toPromise();
// Delete an app file to force a failed compilation.
// Failed compilations still delete files, but don't output any.
await host.delete(join(host.root(), 'src', 'app', 'app.component.ts')).toPromise();
const run = await architect.scheduleTarget(target);
const output = await run.result;
expect(output.success).toBe(false);
expect(await host.exists(join(host.root(), 'dist')).toPromise()).toBe(false);
await run.stop();
});
it('does not allow output path to be project root', async () => {
const overrides = { outputPath: './' };
const run = await architect.scheduleTarget(target, overrides);
try {
await run.result;
expect('THE ABOVE LINE SHOULD THROW').toBe('');
} catch {}
await run.stop();
});
});
示例3: it
it('fails with non-source root input path', async () => {
const assets: { [path: string]: string } = {
'./node_modules/some-package/node_modules-asset.txt': 'node_modules-asset.txt',
};
host.writeMultipleFiles(assets);
const overrides = {
assets: ['not-source-root/file.txt'],
};
const run = await architect.scheduleTarget(targetSpec, overrides);
try {
await run.result;
expect('THE ABOVE LINE SHOULD THROW').toBe('');
} catch {}
// The node_modules folder must be deleted, otherwise code that tries to find the
// node_modules folder will hit this one and can fail.
host.scopedSync().delete(normalize('./node_modules'));
await run.stop();
});
示例4: it
it('keeps escaped charaters', async () => {
host.writeMultipleFiles({
'src/index.html': tags.oneLine`
<html><head><title>í</title><base href="/"></head>
<body><app-root></app-root></body></html>
`,
});
const run = await architect.scheduleTarget(targetSpec);
const output = await run.result as BrowserBuilderOutput;
expect(output.success).toBe(true);
const fileName = join(normalize(output.outputPath), 'index.html');
const content = virtualFs.fileBufferToString(await host.read(normalize(fileName)).toPromise());
expect(content).toBe(
`<html><head><title>í</title><base href="/"></head> `
+ `<body><app-root></app-root><script src="runtime.js"></script>`
+ `<script src="polyfills.js"></script><script src="styles.js"></script>`
+ `<script src="vendor.js"></script><script src="main.js"></script></body></html>`,
);
await run.stop();
});
示例5: expectAsync
it('overrides protractor suites', async () => {
host.scopedSync().rename(
normalize('./e2e/app.e2e-spec.ts'),
normalize('./e2e/renamed-app.e2e-spec.ts'),
);
// Suites block needs to be added in the protractor.conf.js file to test suites
host.replaceInFile('protractor.conf.js', `allScriptsTimeout: 11000,`, `
allScriptsTimeout: 11000,
suites: {
app: './e2e/app.e2e-spec.ts'
},
`);
const overrides = { suite: 'app' };
const run = await architect.scheduleTarget(protractorTargetSpec, overrides);
await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));
await run.stop();
}, 60000);
示例6: it
it('works with watch', async () => {
host.writeMultipleFiles({
'src/my-json-file.json': `{"foo": "1"}`,
'src/main.ts': `import * as a from './my-json-file.json'; console.log(a);`,
});
host.replaceInFile(
'tsconfig.json',
'"target": "es2015"',
'"target": "es5", "resolveJsonModule": true',
);
const overrides = { watch: true };
let buildCount = 1;
const run = await architect.scheduleTarget(target, overrides);
await run.output.pipe(
tap(() => {
const content = virtualFs.fileBufferToString(
host.scopedSync().read(join(outputPath, 'main.js')),
);
switch (buildCount) {
case 1:
expect(content).toContain('foo":"1"');
host.writeMultipleFiles({
'src/my-json-file.json': `{"foo": "2"}`,
});
break;
case 2:
expect(content).toContain('foo":"2"');
break;
}
buildCount++;
}),
tap((buildEvent) => expect(buildEvent.success).toBe(true)),
take(2),
).toPromise();
});
示例7: it
it('ignores missing translations', async () => {
const overrides = {
aot: true,
i18nFile: 'src/locale/messages.fr.xlf',
i18nFormat: 'true',
i18nLocale: 'fr',
i18nMissingTranslation: 'ignore',
};
host.writeMultipleFiles({ 'src/locale/messages.fr.xlf': emptyTranslationFile });
host.appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
const run = await architect.scheduleTarget(targetSpec, overrides);
const output = await run.result as BrowserBuilderOutput;
expect(output.success).toBe(true);
const outputPath = output.outputPath;
const fileName = join(normalize(outputPath), 'main.js');
const content = virtualFs.fileBufferToString(await host.read(normalize(fileName)).toPromise());
expect(content).toMatch(/Other content/);
await run.stop();
});
示例8: it
it(`should show project name as status and in the logs`, async () => {
// Check logs.
const logger = new logging.Logger('lint-info');
const allLogs: string[] = [];
logger.subscribe(entry => allLogs.push(entry.message));
const run = await architect.scheduleTarget(lintTarget, {}, { logger });
// Check status updates.
const allStatus: string[] = [];
run.progress.subscribe(progress => {
if (progress.status !== undefined) {
allStatus.push(progress.status);
}
});
const output = await run.result;
expect(output.success).toBe(true);
expect(allStatus).toContain(jasmine.stringMatching(/linting.*"app".*/i));
expect(allLogs).toContain(jasmine.stringMatching(/linting.*"app".*/i));
await run.stop();
});
示例9: it
it('rebuilds on changes in barrel file dependency', async () => {
host.writeMultipleFiles({
'src/index.ts': `export * from './interface'`,
'src/interface.ts': `export interface Foo { bar: boolean };`,
});
host.appendToFile('src/main.ts', `
import { Foo } from './index';
const x: Foo = { bar: true };
`);
const overrides = { watch: true, aot: false };
let buildNumber = 0;
const run = await architect.scheduleTarget(target, overrides);
await run.output.pipe(
debounceTime(1000),
tap((buildEvent) => {
buildNumber += 1;
switch (buildNumber) {
case 1:
expect(buildEvent.success).toBe(true);
host.writeMultipleFiles({
'src/interface.ts': `export interface Foo {
bar: boolean;
baz?: string;
};`,
});
break;
case 2:
expect(buildEvent.success).toBe(true);
break;
}
}),
take(2),
).toPromise();
await run.stop();
});