Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions tests/legacy-cli/e2e/tests/vitest/larger-project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { ng } from '../../utils/process';
import { applyVitestBuilder } from '../../utils/vitest';
import assert from 'node:assert';
import { installPackage } from '../../utils/packages';
import { exec } from '../../utils/process';

export default async function () {
await applyVitestBuilder();

const artifactCount = 100;
// A new project starts with 1 test file (app.spec.ts)
// Each generated artifact will add one more test file.
const initialTestCount = 1;

// Generate a mix of components, services, and pipes
for (let i = 0; i < artifactCount; i++) {
const type = i % 3;
const name = `test-artifact-${i}`;
let generateType;

switch (type) {
case 0:
generateType = 'component';
break;
case 1:
generateType = 'service';
break;
default:
generateType = 'pipe';
break;
}

await ng('generate', generateType, name, '--skip-tests=false');
}

const totalTests = initialTestCount + artifactCount;
const expectedMessage = new RegExp(`${totalTests} passed`);

// Run tests in default (JSDOM) mode
const { stdout: jsdomStdout } = await ng('test', '--no-watch');
assert.match(jsdomStdout, expectedMessage, `Expected ${totalTests} tests to pass in JSDOM mode.`);

// Setup for browser mode
await installPackage('playwright@1');
await installPackage('@vitest/browser-playwright@4');
await exec('npx', 'playwright', 'install', 'chromium', '--only-shell');

// Run tests in browser mode
const { stdout: browserStdout } = await ng(
'test',
'--no-watch',
'--browsers',
'ChromiumHeadless',
);
assert.match(
browserStdout,
expectedMessage,
`Expected ${totalTests} tests to pass in browser mode.`,
);
}
72 changes: 72 additions & 0 deletions tests/legacy-cli/e2e/tests/vitest/tslib-resolution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { writeFile } from '../../utils/fs';
import { installPackage } from '../../utils/packages';
import { exec, ng } from '../../utils/process';
import { applyVitestBuilder } from '../../utils/vitest';
import assert from 'node:assert';

export default async function () {
await applyVitestBuilder();
await installPackage('playwright@1');
await installPackage('@vitest/browser-playwright@4');
await exec('npx', 'playwright', 'install', 'chromium', '--only-shell');

// Add a custom decorator to trigger tslib usage
await writeFile(
'src/app/custom-decorator.ts',
`
export function MyDecorator() {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
// do nothing
};
}
`,
);

// Add a service that uses the decorator
await writeFile(
'src/app/test.service.ts',
`
import { Injectable } from '@angular/core';
import { MyDecorator } from './custom-decorator';

@Injectable({
providedIn: 'root'
})
export class TestService {
@MyDecorator()
myMethod() {
return true;
}
}
`,
);

// Add a test for the service
await writeFile(
'src/app/test.service.spec.ts',
`
import { TestBed } from '@angular/core/testing';
import { TestService } from './test.service';

describe('TestService', () => {
let service: TestService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TestService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});

it('myMethod should return true', () => {
expect(service.myMethod()).toBe(true);
});
});
`,
);

const { stdout } = await ng('test', '--no-watch', '--browsers', 'chromiumHeadless');
assert.match(stdout, /2 passed/, 'Expected 2 tests to pass.');
}