Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,6 @@ export async function getVitestBuildOptions(

// Find test files
const testFiles = await findTests(include, exclude, workspaceRoot, projectSourceRoot);
if (testFiles.length === 0) {
throw new Error(
'No tests found matching the following patterns:\n' +
`- Included: ${include.join(', ')}\n` +
(exclude.length ? `- Excluded: ${exclude.join(', ')}\n` : '') +
`\nPlease check the 'test' target configuration in your project's 'angular.json' file.`,
);
}

const entryPoints = getTestEntrypoints(testFiles, {
projectSourceRoot,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @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 { execute } from '../../index';
import {
BASE_OPTIONS,
describeBuilder,
UNIT_TEST_BUILDER_INFO,
setupApplicationTarget,
} from '../setup';

describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => {
describe('Behavior: no test files', () => {
beforeEach(() => {
setupApplicationTarget(harness);
});

it('should fail when no tests are discovered and passWithNoTests is not enabled', async () => {
harness.useTarget('test', {
...BASE_OPTIONS,
include: ['**/__no_matching_tests__.spec.ts'],
});

const { result } = await harness.executeOnce();

expect(result?.success).toBeFalse();
});

it('should succeed when no tests are discovered and passWithNoTests is enabled in runnerConfig', async () => {
harness.useTarget('test', {
...BASE_OPTIONS,
include: ['**/__no_matching_tests__.spec.ts'],
runnerConfig: 'vitest.config.mts',
});

harness.writeFile(
'vitest.config.mts',
`
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
passWithNoTests: true,
},
});
`,
);

const { result } = await harness.executeOnce();

expect(result?.success).toBeTrue();
});
});
});
Loading