Skip to content

Commit f4ab9c2

Browse files
committed
WHAT IFFFFFFF THOUGH
1 parent 21b5852 commit f4ab9c2

File tree

7 files changed

+72
-64
lines changed

7 files changed

+72
-64
lines changed

packages/angular/ssr/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"@angular/platform-browser": "20.1.0-next.3",
3636
"@angular/platform-server": "20.1.0-next.3",
3737
"@angular/router": "20.1.0-next.3",
38-
"@schematics/angular": "workspace:*"
38+
"@schematics/angular": "workspace:*",
39+
"vitest": "3.2.4"
3940
},
4041
"sideEffects": false,
4142
"schematics": "./schematics/collection.json",

packages/angular/ssr/test/utils/promise_spec.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,36 @@
99
import { setTimeout } from 'node:timers/promises';
1010
import { promiseWithAbort } from '../../src/utils/promise';
1111

12+
function expectRejectedWithError(promise: Promise<any>) {
13+
if (typeof expectAsync === 'function') {
14+
return expectAsync(promise).toBeRejectedWithError();
15+
} else {
16+
// @ts-expect-error
17+
return expect(promise).rejects.toThrowError();
18+
}
19+
}
20+
21+
function expectResolved(promise: Promise<any>) {
22+
if (typeof expectAsync === 'function') {
23+
return expectAsync(promise).toBeResolved();
24+
} else {
25+
// @ts-expect-error
26+
return expect(promise).resolves;
27+
}
28+
}
29+
1230
describe('promiseWithAbort', () => {
1331
it('should reject with an AbortError when the signal is aborted', async () => {
1432
const abortController = new AbortController();
1533
const promise = promiseWithAbort(setTimeout(500), abortController.signal, 'Test operation');
1634

35+
console.error('queueMicrotask to abort the signal');
1736
queueMicrotask(() => {
1837
abortController.abort('Test reason');
1938
});
2039

21-
await expectAsync(promise).toBeRejectedWithError();
40+
console.error('expectAsync to be rejected with AbortError');
41+
await expectRejectedWithError(promise);
2242
});
2343

2444
it('should not reject if the signal is not aborted', async () => {
@@ -31,6 +51,6 @@ describe('promiseWithAbort', () => {
3151
// Wait briefly to ensure no rejection occurs
3252
await setTimeout(20);
3353

34-
await expectAsync(promise).toBeResolved();
54+
await expectResolved(promise);
3555
});
3656
});

packages/angular/ssr/vitest.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
export default defineConfig({
4+
test: {
5+
include: ['**/*_spec.ts'],
6+
globals: true,
7+
},
8+
});

packages/ngtools/webpack/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"@angular/compiler": "20.1.0-next.3",
3131
"@angular/compiler-cli": "20.1.0-next.3",
3232
"typescript": "5.8.3",
33+
"vitest": "3.2.4",
3334
"webpack": "5.99.9"
3435
}
3536
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
export default defineConfig({
4+
test: {
5+
include: ['**/*_spec.ts'],
6+
globals: true,
7+
},
8+
});

pnpm-lock.yaml

Lines changed: 11 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/vitest_test.bzl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def _vitest_test_impl(ctx):
2+
pass
3+
4+
_vitest_test = rule()
5+
6+
def vitest_test(data = [], args = [], **kwargs):
7+
# Create relative path to root, from current package dir. Necessary as
8+
# we change the `chdir` below to the package directory.
9+
relative_to_root = "/".join([".."] * len(native.package_name().split("/")))
10+
11+
_vitest_test(
12+
node_modules = "//:node_modules",
13+
chdir = native.package_name(),
14+
args = [
15+
# Escape so that the `js_binary` launcher triggers Bash expansion.
16+
"'**/*+(.|_)spec.js'",
17+
] + args,
18+
data = data + ["//:node_modules/vitest"],
19+
**kwargs
20+
)

0 commit comments

Comments
 (0)