"Fossies" - the Fresh Open Source Software Archive

Member "angular-cli-8.3.23/packages/angular_devkit/build_angular/test/browser/allow-js_spec_large.ts" (15 Jan 2020, 3546 Bytes) of package /linux/www/angular-cli-8.3.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /**
    2  * @license
    3  * Copyright Google Inc. All Rights Reserved.
    4  *
    5  * Use of this source code is governed by an MIT-style license that can be
    6  * found in the LICENSE file at https://angular.io/license
    7  */
    8 import { Architect } from '@angular-devkit/architect';
    9 import { join, normalize, relative, virtualFs } from '@angular-devkit/core';
   10 import { take, tap } from 'rxjs/operators';
   11 import { BrowserBuilderOutput } from '../../src/browser';
   12 import { createArchitect, host } from '../utils';
   13 
   14 
   15 describe('Browser Builder allow js', () => {
   16   const targetSpec = { project: 'app', target: 'build' };
   17   let architect: Architect;
   18 
   19   beforeEach(async () => {
   20     await host.initialize().toPromise();
   21     architect = (await createArchitect(host.root())).architect;
   22   });
   23   afterEach(async () => host.restore().toPromise());
   24 
   25   it('works', async () => {
   26     host.writeMultipleFiles({
   27       'src/my-js-file.js': `console.log(1); export const a = 2;`,
   28       'src/main.ts': `import { a } from './my-js-file'; console.log(a);`,
   29     });
   30 
   31     host.replaceInFile(
   32       'tsconfig.json',
   33       '"target": "es2015"',
   34       '"target": "es5", "allowJs": true',
   35     );
   36 
   37     const run = await architect.scheduleTarget(targetSpec);
   38     const output = await run.result as BrowserBuilderOutput;
   39     expect(output.success).toBe(true);
   40 
   41     const content = virtualFs.fileBufferToString(
   42       await host.read(join(normalize(output.outputPath), 'main.js')).toPromise(),
   43     );
   44 
   45     expect(content).toContain('var a = 2');
   46 
   47     await run.stop();
   48   });
   49 
   50   it('works with aot', async () => {
   51     host.writeMultipleFiles({
   52       'src/my-js-file.js': `console.log(1); export const a = 2;`,
   53       'src/main.ts': `import { a } from './my-js-file'; console.log(a);`,
   54     });
   55 
   56     host.replaceInFile(
   57       'tsconfig.json',
   58       '"target": "es2015"',
   59       '"target": "es5", "allowJs": true',
   60     );
   61 
   62     const overrides = { aot: true };
   63 
   64     const run = await architect.scheduleTarget(targetSpec, overrides);
   65     const output = await run.result as BrowserBuilderOutput;
   66     expect(output.success).toBe(true);
   67 
   68     const content = virtualFs.fileBufferToString(
   69       await host.read(join(normalize(output.outputPath), 'main.js')).toPromise(),
   70     );
   71 
   72     expect(content).toContain('var a = 2');
   73 
   74     await run.stop();
   75   });
   76 
   77   it('works with watch', async () => {
   78     host.writeMultipleFiles({
   79       'src/my-js-file.js': `console.log(1); export const a = 2;`,
   80       'src/main.ts': `import { a } from './my-js-file'; console.log(a);`,
   81     });
   82 
   83     host.replaceInFile(
   84       'tsconfig.json',
   85       '"target": "es2015"',
   86       '"target": "es5", "allowJs": true',
   87     );
   88 
   89     const overrides = { watch: true };
   90 
   91     let buildCount = 1;
   92     const run = await architect.scheduleTarget(targetSpec, overrides);
   93 
   94     await run.output.pipe(
   95       tap((output: BrowserBuilderOutput) => {
   96         const path = relative(host.root(), join(normalize(output.outputPath), 'main.js'));
   97         const content = virtualFs.fileBufferToString(
   98           host.scopedSync().read(path),
   99         );
  100 
  101         switch (buildCount) {
  102           case 1:
  103             expect(content).toContain('var a = 2');
  104             host.writeMultipleFiles({
  105               'src/my-js-file.js': `console.log(1); export const a = 1;`,
  106             });
  107             break;
  108           case 2:
  109             expect(content).toContain('var a = 1');
  110             break;
  111         }
  112 
  113         buildCount++;
  114       }),
  115       tap((buildEvent) => expect(buildEvent.success).toBe(true)),
  116       take(2),
  117     ).toPromise();
  118 
  119     await run.stop();
  120   });
  121 });