Skip to content

Commit 73d315a

Browse files
committed
build: improve test resolution
1 parent 2e548e7 commit 73d315a

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

‎angular.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"builder": "@angular/build:unit-test",
4444
"options": {
4545
"buildTarget": "testing-library:test-build-zoneless",
46-
"setupFiles": ["projects/testing-library/test-setup.ts"]
46+
"setupFiles": ["projects/testing-library/test-setup.ts"],
47+
"include": ["**/*.spec.ts", "../zoneless/**/*.spec.ts", "../schematics/**/*.spec.ts"]
4748
}
4849
},
4950
"lint": {

‎projects/testing-library/schematics/migrate-to-zoneless/index.spec.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/te
22
import * as path from 'path';
33
import { EmptyTree } from '@angular-devkit/schematics';
44
import { test, expect } from 'vitest';
5+
import migrateToZoneless from './index';
56

67
test('migrates imports from @testing-library/angular to @testing-library/angular/zoneless', async () => {
78
const before = `
@@ -115,7 +116,7 @@ test('migrates multiple files', async () => {
115116
});
116117

117118
async function setup(files: Record<string, string>) {
118-
const collectionPath = path.join(__dirname, '../../../../dist/@testing-library/angular/schematics/collection.json');
119+
const collectionPath = path.join(__dirname, '../collection.json');
119120
const schematicRunner = new SchematicTestRunner('schematics', collectionPath);
120121

121122
const tree = new UnitTestTree(new EmptyTree());
@@ -124,7 +125,11 @@ async function setup(files: Record<string, string>) {
124125
tree.create(filePath, content);
125126
}
126127

127-
await schematicRunner.runSchematic('migrate-to-zoneless', {}, tree);
128+
// Call the rule directly instead of resolving it through the collection,
129+
// as the collection's factory only exists in compiled output.
130+
await new Promise((resolve, reject) => {
131+
schematicRunner.callRule(migrateToZoneless(), tree).subscribe({ complete: () => resolve(tree), error: reject });
132+
});
128133

129134
return tree;
130135
}

‎projects/testing-library/schematics/migrations/dtl-as-dev-dependency/index.spec.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/te
22
import * as path from 'path';
33
import { EmptyTree } from '@angular-devkit/schematics';
44
import { test, expect } from 'vitest';
5+
import addDtlAsDevDependency from './index';
56

67
test('adds DTL to devDependencies', async () => {
78
const tree = await setup({});
@@ -37,7 +38,11 @@ async function setup(packageJson: object) {
3738
const tree = new UnitTestTree(new EmptyTree());
3839
tree.create('package.json', JSON.stringify(packageJson));
3940

40-
await schematicRunner.runSchematic(`atl-add-dtl-as-dev-dependency`, {}, tree);
41+
// Call the rule directly instead of resolving it through the collection,
42+
// as the collection's factory only exists in compiled output.
43+
await new Promise((resolve, reject) => {
44+
schematicRunner.callRule(addDtlAsDevDependency(), tree).subscribe({ complete: () => resolve(tree), error: reject });
45+
});
4146

4247
return tree;
4348
}

projects/testing-library/src/tests/zoneless.spec.ts renamed to projects/testing-library/zoneless/tests/zoneless.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, inject, Injectable, model, output, outputBinding, signal, twoWayBinding } from '@angular/core';
22
import { test, expect, vi } from 'vitest';
33
import userEvent from '@testing-library/user-event';
4-
import { render, screen } from '../../zoneless';
4+
import { render, screen } from '../index';
55

66
@Injectable()
77
class CounterService {

0 commit comments

Comments
 (0)