當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript virtualFs.stringToFileBuffer方法代碼示例

本文整理匯總了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);
開發者ID:iwe7,項目名稱:devkit,代碼行數:30,代碼來源:host_spec.ts

示例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);
開發者ID:rexebin,項目名稱:angular-cli,代碼行數:35,代碼來源:index_spec.ts

示例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);
開發者ID:DevIntent,項目名稱:angular-cli,代碼行數:33,代碼來源:index_spec.ts

示例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);
  });
開發者ID:fmalcher,項目名稱:angular-cli,代碼行數:27,代碼來源:dryrun_spec.ts

示例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);
  });
開發者ID:DevIntent,項目名稱:angular-cli,代碼行數:31,代碼來源:executor_spec.ts

示例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);
  });
開發者ID:iwe7,項目名稱:devkit,代碼行數:15,代碼來源:executor_spec.ts

示例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);
開發者ID:iwe7,項目名稱:devkit,代碼行數:16,代碼來源:output-path_spec_large.ts

示例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,
      );
    });
開發者ID:iwe7,項目名稱:devkit,代碼行數:16,代碼來源:test-project-host.ts


注:本文中的@angular-devkit/core.virtualFs.stringToFileBuffer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。