angular/packages/compiler-cli/linker/babel/test/babel_plugin_spec.ts
Paul Gschwendtner b7c5645f05 build: migrate packages/compiler-cli to ts_project (#61826)
This commit migrates the remaining pieces of `compiler-cli` to
`ts_project`. This involves a few more things during migration:

- the `ng_module` ngc_wrapped rule broke as part of this change, so we
  switched it to `ts_project` too. This logic is soon gone anyway.

- we needed an extra pnpm "package.json" for the linker babel test. This test is
  loading from the real compiler-cli npm package. Babel needs a real
  node module for this, so this solution seems reasonable. It may be
  worth exploring in the future to move this test into an integration
  test though.

- the older integrationtest in compiler-cli is removed as the coverage
  is much better with the compliance test suite and this test.

PR Close #61826
2025-06-03 11:41:52 +02:00

57 lines
1.9 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import babel from '@babel/core';
import path from 'node:path';
describe('default babel plugin entry-point', () => {
it('should work as a Babel plugin using the module specifier', async () => {
const result = (await babel.transformAsync(
`
import * as i0 from "@angular/core";
export class MyMod {}
export class MyComponent {}
MyMod.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyMod, declarations: [MyComponent] });
`,
{
cwd: path.resolve('./packages/compiler-cli/linker/babel/test'),
plugins: ['@angular/compiler-cli/linker/babel'],
filename: 'test.js',
},
))!;
expect(result).not.toBeNull();
expect(result.code).not.toContain('ɵɵngDeclareNgModule');
expect(result.code).toContain('i0.ɵɵdefineNgModule');
expect(result.code).not.toMatch(/declarations:\s*\[MyComponent]/);
});
it('should be configurable', async () => {
const result = (await babel.transformAsync(
`
import * as i0 from "@angular/core";
export class MyMod {}
export class MyComponent {}
MyMod.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyMod, declarations: [MyComponent] });
`,
{
cwd: path.resolve('./packages/compiler-cli/linker/babel/test'),
plugins: [['@angular/compiler-cli/linker/babel', {linkerJitMode: true}]],
filename: 'test.js',
},
))!;
expect(result).not.toBeNull();
expect(result.code).not.toContain('ɵɵngDeclareNgModule');
expect(result.code).toContain('i0.ɵɵdefineNgModule');
expect(result.code).toMatch(/declarations:\s*\[MyComponent]/);
});
});