Skip to content
Merged
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
33 changes: 33 additions & 0 deletions tests/legacy-cli/e2e/tests/vitest/browser-no-globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import assert from 'node:assert/strict';
import { writeFile } from '../../utils/fs';
import { installPackage } from '../../utils/packages';
import { exec, ng } from '../../utils/process';
import { applyVitestBuilder } from '../../utils/vitest';

/**
* Allow `vitest` import in browser mode.
* @see https://github.com/angular/angular-cli/issues/31745
*/
export default async function (): Promise<void> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given we really need to run in browser mode to reproduce the bug, I had to install the packages so I went with an e2e.

Any narrower test would be over-specifying and not provide enough confidence.

await applyVitestBuilder();

await installPackage('playwright@1');
await installPackage('@vitest/browser-playwright@4');

await exec('npx', 'playwright', 'install', 'chromium', '--only-shell');

await writeFile(
'src/app/app.spec.ts',
`
import { test, expect } from 'vitest';

test('should pass', () => {
expect(true).toBe(true);
});
`,
);

const { stdout } = await ng('test', '--browsers', 'ChromiumHeadless');

assert.match(stdout, /1 passed/, 'Expected 1 tests to pass.');
}