本文整理汇总了TypeScript中@angular-devkit/core.virtualFs.stringToFileBuffer方法的典型用法代码示例。如果您正苦于以下问题:TypeScript virtualFs.stringToFileBuffer方法的具体用法?TypeScript virtualFs.stringToFileBuffer怎么用?TypeScript virtualFs.stringToFileBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular-devkit/core.virtualFs
的用法示例。
在下文中一共展示了virtualFs.stringToFileBuffer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: linuxOnlyIt
linuxOnlyIt('can watch', done => {
let obs: Observable<virtualFs.HostWatchEvent>;
let subscription: Subscription;
const content = virtualFs.stringToFileBuffer('hello world');
const content2 = virtualFs.stringToFileBuffer('hello world 2');
const allEvents: virtualFs.HostWatchEvent[] = [];
Promise.resolve()
.then(() => fs.mkdirSync(root + '/sub1'))
.then(() => fs.writeFileSync(root + '/sub1/file1', 'hello world'))
.then(() => {
obs = host.watch(normalize('/sub1'), { recursive: true })!;
expect(obs).not.toBeNull();
subscription = obs.subscribe(event => { allEvents.push(event); });
})
.then(() => new Promise(resolve => setTimeout(resolve, 100)))
// Discard the events registered so far.
.then(() => allEvents.splice(0))
.then(() => {
host.write(normalize('/sub1/sub2/file3'), content);
host.write(normalize('/sub1/file2'), content2);
host.delete(normalize('/sub1/file1'));
})
.then(() => new Promise(resolve => setTimeout(resolve, 2000)))
.then(() => {
expect(allEvents.length).toBe(3);
subscription.unsubscribe();
})
.then(done, done.fail);
}, 30000);
示例2: it
it('calls migration tasks', done => {
// Add the basic migration package.
const content = virtualFs.fileBufferToString(host.sync.read(normalize('/package.json')));
const packageJson = JSON.parse(content);
packageJson['dependencies']['@angular-devkit-tests/update-migrations'] = '1.0.0';
host.sync.write(
normalize('/package.json'),
virtualFs.stringToFileBuffer(JSON.stringify(packageJson)),
);
schematicRunner.runSchematicAsync('update', { all: true }, appTree).pipe(
map(tree => {
const packageJson = JSON.parse(tree.readContent('/package.json'));
expect(packageJson['dependencies']['@angular-devkit-tests/update-base']).toBe('1.1.0');
expect(packageJson['dependencies']['@angular-devkit-tests/update-migrations'])
.toBe('1.6.0');
// Check install task.
expect(schematicRunner.tasks).toEqual([
{
name: 'node-package',
options: jasmine.objectContaining({
command: 'install',
}),
},
{
name: 'run-schematic',
options: jasmine.objectContaining({
name: 'migrate',
}),
},
]);
}),
).toPromise().then(done, done.fail);
}, 45000);
示例3: it
it('uses packageGroup for versioning', async () => {
// Add the basic migration package.
const content = virtualFs.fileBufferToString(host.sync.read(normalize('/package.json')));
const packageJson = JSON.parse(content);
const dependencies = packageJson['dependencies'];
dependencies['@angular-devkit-tests/update-package-group-1'] = '1.0.0';
dependencies['@angular-devkit-tests/update-package-group-2'] = '1.0.0';
host.sync.write(
normalize('/package.json'),
virtualFs.stringToFileBuffer(JSON.stringify(packageJson)),
);
await schematicRunner.runSchematicAsync('update', {
packages: ['@angular-devkit-tests/update-package-group-1'],
}, appTree).pipe(
map(tree => {
const packageJson = JSON.parse(tree.readContent('/package.json'));
const deps = packageJson['dependencies'];
expect(deps['@angular-devkit-tests/update-package-group-1']).toBe('1.2.0');
expect(deps['@angular-devkit-tests/update-package-group-2']).toBe('2.0.0');
// Check install task.
expect(schematicRunner.tasks).toEqual([
{
name: 'node-package',
options: jasmine.objectContaining({
command: 'install',
}),
},
]);
}),
).toPromise();
}, 45000);
示例4: it
it('works with root', done => {
const tree = new FileSystemTree(host);
tree.create('/test', 'testing 1 2');
const recorder = tree.beginUpdate('/test');
recorder.insertLeft(8, 'testing ');
tree.commitUpdate(recorder);
tree.overwrite('/hello', 'world');
const files = ['/hello', '/sub/directory/file2', '/sub/file1', '/test'];
expect(tree.files.sort()).toEqual(files.map(normalize));
// Need to create this file on the filesystem, otherwise the commit phase will fail.
const outputHost = new virtualFs.SimpleMemoryHost();
outputHost.write(normalize('/hello'), virtualFs.stringToFileBuffer('')).subscribe();
const sink = new DryRunSink(outputHost);
sink.reporter.pipe(toArray())
.toPromise()
.then(infos => {
expect(infos.map(x => x.kind)).toEqual(['create', 'update']);
})
.then(done, done.fail);
sink.commit(optimize(tree))
.toPromise().then(done, done.fail);
});
示例5: it
it('supports custom rules in the project (pass)', done => {
// This test is disabled on Windows Bazel runs because it relies on TSLint custom rule
// loading behavior, which doesn't work with runfile resolution.
if (isWindowsBazel) {
done();
return;
}
const testRunner = new SchematicTestRunner(
'@_/test',
require.resolve('./test/collection.json'),
);
const host = new TempScopedNodeJsSyncHost();
host.write(normalize('/file.ts'), virtualFs.stringToFileBuffer(`
console.log('hello world');
`)).subscribe();
const tree = new UnitTestTree(new HostTree(host));
const messages: string[] = [];
concat(
testRunner.runSchematicAsync('custom-rule', { shouldPass: true }, tree),
new Observable<void>(obs => {
process.chdir(getSystemPath(host.root));
testRunner.logger.subscribe(x => messages.push(x.message));
testRunner.engine.executePostTasks().subscribe(obs);
}),
).toPromise().then(done, done.fail);
});
示例6: it
it('works with config object', done => {
const testRunner = new SchematicTestRunner(
'@_/test',
path.join(__dirname, 'test/collection.json'),
);
const host = new TempScopedNodeJsSyncHost();
host.write(normalize('/file.ts'), virtualFs.stringToFileBuffer(`
export function() { console.log(1); }
`)).subscribe();
const tree = new UnitTestTree(new HostTree(host));
testRunner.runSchematicAsync('run-task', null, tree)
.subscribe(undefined, done.fail, done);
});
示例7: it
it('deletes output path', (done) => {
// Write a file to the output path to later verify it was deleted.
host.scopedSync().write(join(outputPath, 'file.txt'), virtualFs.stringToFileBuffer('file'));
// Delete an app file to force a failed compilation.
// Failed compilations still delete files, but don't output any.
host.delete(join(workspaceRoot, 'src', 'app', 'app.component.ts')).subscribe({
error: done.fail,
});
runTargetSpec(host, browserTargetSpec).pipe(
tap((buildEvent) => {
expect(buildEvent.success).toBe(false);
expect(host.scopedSync().exists(outputPath)).toBe(false);
}),
).subscribe(undefined, done.fail, done);
}, Timeout.Basic);
示例8: if
Object.keys(files).map(fileName => {
let content = files[fileName];
if (typeof content == 'string') {
content = virtualFs.stringToFileBuffer(content);
} else if (content instanceof Buffer) {
content = content.buffer.slice(
content.byteOffset,
content.byteOffset + content.byteLength,
);
}
this.scopedSync().write(
normalize(fileName),
content,
);
});