|
| 1 | +import { getGlobalVariable } from '../../utils/env'; |
| 2 | +import { expectFileToMatch, replaceInFile, writeFile } from '../../utils/fs'; |
| 3 | +import { ng, npm } from '../../utils/process'; |
| 4 | +import { expectToFail } from '../../utils/utils'; |
| 5 | +import { readNgVersion } from '../../utils/version'; |
| 6 | + |
| 7 | +export default async function() { |
| 8 | + // Ivy only test |
| 9 | + if (getGlobalVariable('argv')['ve']) { |
| 10 | + return; |
| 11 | + } |
| 12 | + |
| 13 | + // Setup a library |
| 14 | + await ng('generate', 'library', 'i18n-lib-test'); |
| 15 | + await replaceInFile( |
| 16 | + 'projects/i18n-lib-test/src/lib/i18n-lib-test.component.ts', |
| 17 | + '<p>', |
| 18 | + '<p i18n>', |
| 19 | + ); |
| 20 | + |
| 21 | + // Build library |
| 22 | + await ng('build', 'i18n-lib-test'); |
| 23 | + |
| 24 | + // Consume library in application |
| 25 | + await writeFile( |
| 26 | + 'src/app/app.module.ts', |
| 27 | + ` |
| 28 | + import { BrowserModule } from '@angular/platform-browser'; |
| 29 | + import { NgModule } from '@angular/core'; |
| 30 | + import { AppComponent } from './app.component'; |
| 31 | + import { I18nLibTestModule } from 'i18n-lib-test'; |
| 32 | +
|
| 33 | + @NgModule({ |
| 34 | + declarations: [ |
| 35 | + AppComponent |
| 36 | + ], |
| 37 | + imports: [ |
| 38 | + BrowserModule, |
| 39 | + I18nLibTestModule, |
| 40 | + ], |
| 41 | + providers: [], |
| 42 | + bootstrap: [AppComponent] |
| 43 | + }) |
| 44 | + export class AppModule { } |
| 45 | + `, |
| 46 | + ); |
| 47 | + |
| 48 | + await writeFile( |
| 49 | + 'src/app/app.component.html', |
| 50 | + ` |
| 51 | + <p i18n>Hello world</p> |
| 52 | + <lib-i18n-lib-test></lib-i18n-lib-test> |
| 53 | + `, |
| 54 | + ); |
| 55 | + |
| 56 | + // Install correct version |
| 57 | + let localizeVersion = '@angular/localize@' + readNgVersion(); |
| 58 | + if (getGlobalVariable('argv')['ng-snapshots']) { |
| 59 | + localizeVersion = require('../../ng-snapshot/package.json').dependencies['@angular/localize']; |
| 60 | + } |
| 61 | + await npm('install', `${localizeVersion}`); |
| 62 | + |
| 63 | + // Extract messages |
| 64 | + await ng('xi18n', '--ivy'); |
| 65 | + await expectFileToMatch('messages.xlf', 'src/app/app.component.html'); |
| 66 | + await expectFileToMatch('messages.xlf', 'Hello world'); |
| 67 | + await expectFileToMatch('messages.xlf', 'i18n-lib-test works!'); |
| 68 | + await expectFileToMatch( |
| 69 | + 'messages.xlf', |
| 70 | + `projects/i18n-lib-test/src/lib/i18n-lib-test.component.ts`, |
| 71 | + ); |
| 72 | +} |
0 commit comments