-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
521 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/@o3r/components/builders/component-extractor/index.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Architect } from '@angular-devkit/architect'; | ||
import { TestingArchitectHost } from '@angular-devkit/architect/testing'; | ||
import { schema } from '@angular-devkit/core'; | ||
import { cleanVirtualFileSystem, useVirtualFileSystem } from '@o3r/test-helpers'; | ||
import * as fs from 'node:fs'; | ||
import * as path from 'node:path'; | ||
import { ComponentExtractorBuilderSchema } from './schema'; | ||
|
||
describe('Component Extractor Builder', () => { | ||
const workspaceRoot = path.join('..', '..', '..', '..', '..'); | ||
let architect: Architect; | ||
let architectHost: TestingArchitectHost; | ||
let virtualFileSystem: typeof fs; | ||
|
||
beforeEach(async () => { | ||
virtualFileSystem = useVirtualFileSystem(); | ||
|
||
const registry = new schema.CoreSchemaRegistry(); | ||
registry.addPostTransform(schema.transforms.addUndefinedDefaults); | ||
architectHost = new TestingArchitectHost(path.resolve(__dirname, workspaceRoot), __dirname); | ||
architect = new Architect(architectHost, registry); | ||
await architectHost.addBuilderFromPackage(path.resolve(__dirname, '..', '..')); | ||
}); | ||
afterEach(() => { | ||
cleanVirtualFileSystem(); | ||
}); | ||
|
||
it('should extract components', async () => { | ||
const options: ComponentExtractorBuilderSchema = { | ||
tsConfig: 'apps/showcase/tsconfig.cms.json', | ||
configOutputFile: path.resolve(__dirname, `${workspaceRoot}/apps/showcase/component.config.metadata.json`), | ||
componentOutputFile: path.resolve(__dirname, `${workspaceRoot}/apps/showcase/component.class.metadata.json`), | ||
name: 'showcase', | ||
libraries: [], | ||
placeholdersMetadataFilePath: path.resolve(__dirname, `${workspaceRoot}/apps/showcase/placeholders.metadata.manual.json`), | ||
exposedComponentSupport: true, | ||
globalConfigCategories: [ | ||
{ name: 'globalCategory', label: 'Global category' } | ||
], | ||
filePattern: 'src/**/*.(component|config|module).ts', | ||
inline: false, | ||
strictMode: false, | ||
watch: false | ||
}; | ||
const run = await architect.scheduleBuilder('@o3r/components:extractor', options); | ||
const output = await run.result; | ||
expect(output.error).toBe(undefined); | ||
await run.stop(); | ||
|
||
const componentOutput = JSON.parse(virtualFileSystem.readFileSync(options.componentOutputFile, {encoding: 'utf8'})); | ||
expect(typeof componentOutput).toBe('object'); | ||
expect(typeof componentOutput.length).toBe('number'); | ||
expect(componentOutput[0].library).toBe('showcase'); | ||
expect(componentOutput[0].name).toMatch(/.*Component$/); | ||
expect(componentOutput[0].path).toMatch(/.*component.ts$/); | ||
expect(componentOutput[0].templatePath).toMatch(/.*template.html$/); | ||
|
||
const configOutput = JSON.parse(virtualFileSystem.readFileSync(options.configOutputFile, {encoding: 'utf8'})); | ||
expect(typeof configOutput).toBe('object'); | ||
expect(typeof configOutput.length).toBe('number'); | ||
expect(configOutput[0].library).toBe('showcase'); | ||
expect(configOutput[0].name).toMatch(/.*Config$/); | ||
expect(configOutput[0].path).toMatch(/.*config.ts$/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
import 'jest-preset-angular/setup-jest'; | ||
|
||
global.setImmediate ||= ((fn: any, ...args: any) => { | ||
// eslint-disable-next-line @typescript-eslint/no-implied-eval | ||
const ref = global.setTimeout(fn, 0, ...args); | ||
jest.runAllTimers(); | ||
return ref; | ||
}) as any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Architect } from '@angular-devkit/architect'; | ||
import { TestingArchitectHost } from '@angular-devkit/architect/testing'; | ||
import { schema } from '@angular-devkit/core'; | ||
import { cleanVirtualFileSystem, useVirtualFileSystem } from '@o3r/test-helpers'; | ||
import * as fs from 'node:fs'; | ||
import * as path from 'node:path'; | ||
import { I18nBuilderSchema } from './schema'; | ||
|
||
describe('Localization i18n Builder', () => { | ||
const workspaceRoot = path.join('..', '..', '..', '..', '..'); | ||
let architect: Architect; | ||
let architectHost: TestingArchitectHost; | ||
let virtualFileSystem: typeof fs; | ||
|
||
beforeEach(async () => { | ||
virtualFileSystem = useVirtualFileSystem(); | ||
|
||
const registry = new schema.CoreSchemaRegistry(); | ||
registry.addPostTransform(schema.transforms.addUndefinedDefaults); | ||
architectHost = new TestingArchitectHost(path.resolve(__dirname, workspaceRoot), __dirname); | ||
architect = new Architect(architectHost, registry); | ||
await architectHost.addBuilderFromPackage(path.resolve(__dirname, '..', '..')); | ||
}); | ||
afterEach(() => { | ||
cleanVirtualFileSystem(); | ||
}); | ||
|
||
it('should generate the i18n', async () => { | ||
const i18nFolder = path.resolve(__dirname, `${workspaceRoot}/apps/showcase/src/components/showcase/localization/i18n`); | ||
await virtualFileSystem.promises.mkdir(i18nFolder, {recursive: true}); | ||
const options: I18nBuilderSchema = { | ||
localizationConfigs: [ | ||
{ | ||
localizationFiles: [ | ||
'apps/showcase/src/!(i18n)/**/*.localization.json' | ||
], | ||
i18nFolderPath: 'i18n' | ||
} | ||
], | ||
defaultLanguageFile: 'en-GB.json' | ||
}; | ||
const run = await architect.scheduleBuilder('@o3r/localization:i18n', options); | ||
const output = await run.result; | ||
expect(output.error).toBe(undefined); | ||
await run.stop(); | ||
|
||
const i18nOutput = JSON.parse(virtualFileSystem.readFileSync(path.join(i18nFolder, 'en-GB.json'), {encoding: 'utf8'})); | ||
expect(typeof i18nOutput).toBe('object'); | ||
expect(Object.keys(i18nOutput)[0]).toMatch(/o3r-.*/); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
packages/@o3r/localization/builders/localization-extractor/index.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Architect } from '@angular-devkit/architect'; | ||
import { TestingArchitectHost } from '@angular-devkit/architect/testing'; | ||
import { schema } from '@angular-devkit/core'; | ||
import { cleanVirtualFileSystem, useVirtualFileSystem } from '@o3r/test-helpers'; | ||
import * as fs from 'node:fs'; | ||
import * as path from 'node:path'; | ||
import { LocalizationExtractorBuilderSchema } from './schema'; | ||
|
||
describe('Localization Extractor Builder', () => { | ||
const workspaceRoot = path.join('..', '..', '..', '..', '..'); | ||
let architect: Architect; | ||
let architectHost: TestingArchitectHost; | ||
let virtualFileSystem: typeof fs; | ||
|
||
beforeEach(async () => { | ||
virtualFileSystem = useVirtualFileSystem(); | ||
|
||
const registry = new schema.CoreSchemaRegistry(); | ||
registry.addPostTransform(schema.transforms.addUndefinedDefaults); | ||
architectHost = new TestingArchitectHost(path.resolve(__dirname, workspaceRoot), __dirname); | ||
architect = new Architect(architectHost, registry); | ||
await architectHost.addBuilderFromPackage(path.resolve(__dirname, '..', '..')); | ||
}); | ||
afterEach(() => { | ||
cleanVirtualFileSystem(); | ||
}); | ||
|
||
it('should extract the localizations', async () => { | ||
const options: LocalizationExtractorBuilderSchema = { | ||
tsConfig: 'apps/showcase/tsconfig.cms.json', | ||
outputFile: path.resolve(__dirname, `${workspaceRoot}/apps/showcase/localisation.metadata.json`), | ||
libraries: [], | ||
extraFilePatterns: [ | ||
'src/i18n/*.localization.json' | ||
], | ||
watch: false, | ||
ignoreDuplicateKeys: false, | ||
inline: false, | ||
sortKeys: false | ||
}; | ||
const run = await architect.scheduleBuilder('@o3r/localization:extractor', options); | ||
const output = await run.result; | ||
expect(output.error).toBe(undefined); | ||
await run.stop(); | ||
|
||
const localizationOutput = JSON.parse(virtualFileSystem.readFileSync(options.outputFile, {encoding: 'utf8'})); | ||
expect(typeof localizationOutput).toBe('object'); | ||
expect(typeof localizationOutput.length).toBe('number'); | ||
expect(localizationOutput[0].key).toMatch(/o3r-.*/); | ||
}); | ||
}); |
72 changes: 72 additions & 0 deletions
72
packages/@o3r/localization/builders/localization/index.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {Architect, createBuilder} from '@angular-devkit/architect'; | ||
import { TestingArchitectHost } from '@angular-devkit/architect/testing'; | ||
import { schema } from '@angular-devkit/core'; | ||
import { cleanVirtualFileSystem, useVirtualFileSystem } from '@o3r/test-helpers'; | ||
import * as fs from 'node:fs'; | ||
import * as path from 'node:path'; | ||
import { of } from 'rxjs'; | ||
import { LocalizationBuilderSchema } from './schema'; | ||
|
||
describe('Localization Builder', () => { | ||
const workspaceRoot = path.join('..', '..', '..', '..', '..'); | ||
let architect: Architect; | ||
let architectHost: TestingArchitectHost; | ||
let virtualFileSystem: typeof fs; | ||
|
||
beforeEach(async () => { | ||
virtualFileSystem = useVirtualFileSystem(); | ||
|
||
const registry = new schema.CoreSchemaRegistry(); | ||
registry.addPostTransform(schema.transforms.addUndefinedDefaults); | ||
architectHost = new TestingArchitectHost(path.resolve(__dirname, workspaceRoot), __dirname); | ||
architect = new Architect(architectHost, registry); | ||
await architectHost.addBuilderFromPackage(path.resolve(__dirname, '..', '..')); | ||
architectHost.addBuilder('noop', createBuilder(() => of({success: true})), '', { | ||
type: 'object', | ||
additionalProperties: true | ||
}); | ||
architectHost.addTarget({project: 'showcase', target: 'compile'}, 'noop', { | ||
outputPath: path.resolve(__dirname, `${workspaceRoot}/apps/showcase/dist`) | ||
}); | ||
architectHost.addTarget({project: 'showcase', target: 'extract-translations'}, 'noop', { | ||
outputFile: path.resolve(__dirname, `${workspaceRoot}/apps/showcase/localisation.metadata.json`) | ||
}); | ||
await virtualFileSystem.promises.mkdir(path.resolve(__dirname, `${workspaceRoot}/apps/showcase`), {recursive: true}); | ||
await virtualFileSystem.promises.writeFile(path.resolve(__dirname, `${workspaceRoot}/apps/showcase/localisation.metadata.json`), '[]'); | ||
}); | ||
afterEach(() => { | ||
cleanVirtualFileSystem(); | ||
}); | ||
|
||
it('should genere the localizations', async () => { | ||
const options: LocalizationBuilderSchema = { | ||
browserTarget: 'showcase:compile', | ||
localizationExtracterTarget: 'showcase:extract-translations', | ||
locales: [ | ||
'en-GB', | ||
'fr-FR' | ||
], | ||
assets: [ | ||
'apps/showcase/src/assets/locales', | ||
'apps/showcase/src/assets/locales/*', | ||
'apps/showcase/src/components/**/i18n' | ||
], | ||
outputPath: path.resolve(__dirname, `${workspaceRoot}/apps/showcase/dev-resources/localizations`), | ||
checkUnusedTranslation: true, | ||
defaultLanguageMapping: {}, | ||
failIfMissingMetadata: false, | ||
watch: false, | ||
ignoreReferencesIfNotDefault: false, | ||
useMetadataAsDefault: true | ||
}; | ||
await virtualFileSystem.promises.mkdir(options.outputPath, {recursive: true}); | ||
const run = await architect.scheduleBuilder('@o3r/localization:localization', options); | ||
const output = await run.result; | ||
expect(output.error).toBe(undefined); | ||
await run.stop(); | ||
|
||
const localizationOutput = virtualFileSystem.readdirSync(options.outputPath); | ||
expect(localizationOutput).toContain('en-GB.json'); | ||
expect(localizationOutput).toContain('fr-FR.json'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
import 'jest-preset-angular/setup-jest'; | ||
import 'isomorphic-fetch'; | ||
|
||
global.setImmediate ||= ((fn: any, ...args: any) => { | ||
// eslint-disable-next-line @typescript-eslint/no-implied-eval | ||
const ref = global.setTimeout(fn, 0, ...args); | ||
jest.runAllTimers(); | ||
return ref; | ||
}) as any; |
Oops, something went wrong.