Skip to content

Commit

Permalink
test: use esbuild-based karma builder for e2e tests in esbuild suite
Browse files Browse the repository at this point in the history
Updated the E2E tests to use the esbuild-based karma builder when running the esbuild test suite.
  • Loading branch information
alan-agius4 committed Feb 14, 2025
1 parent 486d477 commit 0599580
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 35 deletions.
26 changes: 0 additions & 26 deletions tests/legacy-cli/e2e/tests/misc/karma-error-paths.ts

This file was deleted.

4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/test/test-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default async function () {

// prepare global scripts test files
await writeMultipleFiles({
'src/string-script.js': `stringScriptGlobal = 'string-scripts.js';`,
'src/input-script.js': `inputScriptGlobal = 'input-scripts.js';`,
'src/string-script.js': `globalThis.stringScriptGlobal = 'string-scripts.js';`,
'src/input-script.js': `globalThis.inputScriptGlobal = 'input-scripts.js';`,
'src/typings.d.ts': `
declare var stringScriptGlobal: any;
declare var inputScriptGlobal: any;
Expand Down
21 changes: 14 additions & 7 deletions tests/legacy-cli/e2e/tests/test/test-sourcemap.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import assert from 'node:assert';
import { getGlobalVariable } from '../../utils/env';
import { writeFile } from '../../utils/fs';
import { ng } from '../../utils/process';
import { assertIsError } from '../../utils/utils';

export default async function () {
if (getGlobalVariable('argv')['esbuild']) {
// TODO: enable once this is fixed when using the esbuild builder.
return;
}

await writeFile(
'src/app/app.component.spec.ts',
`
it('show fail', () => {
it('should fail', () => {
expect(undefined).toBeTruthy();
});
`,
Expand All @@ -16,18 +24,17 @@ export default async function () {
await ng('test', '--no-watch', '--source-map');
throw new Error('ng test should have failed.');
} catch (error) {
if (!(error instanceof Error && error.message.includes('app.component.spec.ts'))) {
throw error;
}
assertIsError(error);
assert.match(error.message, /src\/app\/app\.component\.spec\.ts/);
assert.doesNotMatch(error.message, /_karma_webpack_/);
}

// when sourcemaps are 'off' the stacktrace won't point to the spec.ts file.
try {
await ng('test', '--no-watch', '--no-source-map');
throw new Error('ng test should have failed.');
} catch (error) {
if (!(error instanceof Error && error.message.includes('main.js'))) {
throw error;
}
assertIsError(error);
assert.match(error.message, /main\.js/);
}
}
3 changes: 3 additions & 0 deletions tests/legacy-cli/e2e/utils/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ export async function useCIChrome(projectName: string, projectDir = ''): Promise
const project = workspaceJson.projects[projectName];
const appTargets = project.targets || project.architect;
appTargets.test.options.browsers = 'ChromeHeadlessNoSandbox';
appTargets.test.options.builderMode = getGlobalVariable('argv')['esbuild']
? 'application'
: 'browser';
});
}

Expand Down

0 comments on commit 0599580

Please sign in to comment.