Skip to content

Commit e843cb6

Browse files
committed
test(@angular/build): add e2e for tslib resolution in Vitest
Adds an end-to-end test to verify that tslib is correctly resolved when using custom decorators within Vitest unit tests. This ensures compatibility with Angular decorators and the Vitest runner's module resolution configuration. (cherry picked from commit f4a7cd9)
1 parent 49b65ab commit e843cb6

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { writeFile } from '../../utils/fs';
2+
import { installPackage } from '../../utils/packages';
3+
import { exec, ng } from '../../utils/process';
4+
import { applyVitestBuilder } from '../../utils/vitest';
5+
import assert from 'node:assert';
6+
7+
export default async function () {
8+
await applyVitestBuilder();
9+
await installPackage('playwright@1');
10+
await installPackage('@vitest/browser-playwright@4');
11+
await exec('npx', 'playwright', 'install', 'chromium', '--only-shell');
12+
13+
// Add a custom decorator to trigger tslib usage
14+
await writeFile(
15+
'src/app/custom-decorator.ts',
16+
`
17+
export function MyDecorator() {
18+
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
19+
// do nothing
20+
};
21+
}
22+
`,
23+
);
24+
25+
// Add a service that uses the decorator
26+
await writeFile(
27+
'src/app/test.service.ts',
28+
`
29+
import { Injectable } from '@angular/core';
30+
import { MyDecorator } from './custom-decorator';
31+
32+
@Injectable({
33+
providedIn: 'root'
34+
})
35+
export class TestService {
36+
@MyDecorator()
37+
myMethod() {
38+
return true;
39+
}
40+
}
41+
`,
42+
);
43+
44+
// Add a test for the service
45+
await writeFile(
46+
'src/app/test.service.spec.ts',
47+
`
48+
import { TestBed } from '@angular/core/testing';
49+
import { TestService } from './test.service';
50+
51+
describe('TestService', () => {
52+
let service: TestService;
53+
54+
beforeEach(() => {
55+
TestBed.configureTestingModule({});
56+
service = TestBed.inject(TestService);
57+
});
58+
59+
it('should be created', () => {
60+
expect(service).toBeTruthy();
61+
});
62+
63+
it('myMethod should return true', () => {
64+
expect(service.myMethod()).toBe(true);
65+
});
66+
});
67+
`,
68+
);
69+
70+
const { stdout } = await ng('test', '--no-watch', '--browsers', 'chromiumHeadless');
71+
assert.match(stdout, /2 passed/, 'Expected 2 tests to pass.');
72+
}

0 commit comments

Comments
 (0)