Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d95bb63

Browse files
committed
refactor: make tests compatible with @types/mocha
Mocha global types will get pulled in by Web Test Runner, unfortunately. So we need to make our tests match that API syntax. TODO: Should we shift the dependency to `@web/test-runner-core` instead to avoid this dep?
1 parent 47f4c77 commit d95bb63

File tree

6 files changed

+36
-63
lines changed

6 files changed

+36
-63
lines changed

packages/angular_devkit/build_angular/src/builders/browser/specs/styles_spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,12 @@ describe('Browser Builder styles', () => {
327327
});
328328

329329
// TODO: consider making this a unit test in the url processing plugins.
330-
it(
330+
const jasmineIt = it as (
331+
expectation: string,
332+
assertion: jasmine.ImplementationCallback,
333+
timeout?: number,
334+
) => void;
335+
jasmineIt(
331336
`supports baseHref/deployUrl in resource urls`,
332337
async () => {
333338
// Use a large image for the relative ref so it cannot be inlined.

packages/angular_devkit/build_angular/src/builders/browser/tests/options/watch_spec.ts

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { concatMap, count, take, timeout } from 'rxjs';
9+
import { concatMap, count, firstValueFrom, map, take, timeout, toArray } from 'rxjs';
1010
import { buildWebpackBrowser } from '../../index';
1111
import { BASE_OPTIONS, BROWSER_BUILDER_INFO, describeBuilder } from '../setup';
1212

@@ -17,57 +17,43 @@ describeBuilder(buildWebpackBrowser, BROWSER_BUILDER_INFO, (harness) => {
1717
await harness.writeFile('src/main.ts', '');
1818
});
1919

20-
it('does not wait for file changes when false', (done) => {
20+
it('does not wait for file changes when false', async () => {
2121
harness.useTarget('build', {
2222
...BASE_OPTIONS,
2323
watch: false,
2424
});
2525

26-
// If the build waits then it will timeout with the custom timeout.
27-
// A single build should not take more than 15 seconds.
28-
let count = 0;
29-
harness
30-
.execute()
31-
.pipe(timeout(15000))
32-
.subscribe({
33-
complete() {
34-
expect(count).toBe(1);
35-
done();
36-
},
37-
next({ result }) {
38-
count++;
39-
expect(result?.success).toBe(true);
40-
},
41-
error(error) {
42-
done.fail(error);
43-
},
44-
});
26+
const results = await firstValueFrom(
27+
harness.execute().pipe(
28+
// If the build waits then it will timeout with the custom timeout.
29+
// A single build should not take more than 15 seconds.
30+
timeout(15000),
31+
map(({ result }) => result),
32+
toArray(),
33+
),
34+
);
35+
36+
expect(results.length).toBe(1);
37+
expect(results[0]?.success).toBe(true);
4538
});
4639

47-
it('does not wait for file changes when not present', (done) => {
40+
it('does not wait for file changes when not present', async () => {
4841
harness.useTarget('build', {
4942
...BASE_OPTIONS,
5043
});
5144

5245
// If the build waits then it will timeout with the custom timeout.
5346
// A single build should not take more than 15 seconds.
54-
let count = 0;
55-
harness
56-
.execute()
57-
.pipe(timeout(15000))
58-
.subscribe({
59-
complete() {
60-
expect(count).toBe(1);
61-
done();
62-
},
63-
next({ result }) {
64-
count++;
65-
expect(result?.success).toBe(true);
66-
},
67-
error(error) {
68-
done.fail(error);
69-
},
70-
});
47+
const results = await firstValueFrom(
48+
harness.execute().pipe(
49+
timeout(15000),
50+
map(({ result }) => result),
51+
toArray(),
52+
),
53+
);
54+
55+
expect(results.length).toBe(1);
56+
expect(results[0]?.success).toBeTrue();
7157
});
7258

7359
it('watches for file changes when true', async () => {

packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-static-class-members_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function testCase({
2121
input: string;
2222
expected: string | typeof NO_CHANGE;
2323
options?: { wrapDecorators?: boolean };
24-
}): jasmine.ImplementationCallback {
24+
}) {
2525
return async () => {
2626
const result = transformSync(input, {
2727
configFile: false,

packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-typescript-enums_spec.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ import adjustTypeScriptEnums from './adjust-typescript-enums';
1313

1414
const NO_CHANGE = Symbol('NO_CHANGE');
1515

16-
function testCase({
17-
input,
18-
expected,
19-
}: {
20-
input: string;
21-
expected: string | typeof NO_CHANGE;
22-
}): jasmine.ImplementationCallback {
16+
function testCase({ input, expected }: { input: string; expected: string | typeof NO_CHANGE }) {
2317
return async () => {
2418
const result = transformSync(input, {
2519
configFile: false,

packages/angular_devkit/build_angular/src/tools/babel/plugins/elide-angular-metadata_spec.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ import { transformSync } from '@babel/core';
1111
import { format } from 'prettier';
1212
import elideAngularMetadata from './elide-angular-metadata';
1313

14-
function testCase({
15-
input,
16-
expected,
17-
}: {
18-
input: string;
19-
expected: string;
20-
}): jasmine.ImplementationCallback {
14+
function testCase({ input, expected }: { input: string; expected: string }) {
2115
return async () => {
2216
const result = transformSync(input, {
2317
configFile: false,

packages/angular_devkit/build_angular/src/tools/babel/plugins/pure-toplevel-functions_spec.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ import { transformSync } from '@babel/core';
1111
import { format } from 'prettier';
1212
import pureTopLevelPlugin from './pure-toplevel-functions';
1313

14-
function testCase({
15-
input,
16-
expected,
17-
}: {
18-
input: string;
19-
expected: string;
20-
}): jasmine.ImplementationCallback {
14+
function testCase({ input, expected }: { input: string; expected: string }) {
2115
return async () => {
2216
const result = transformSync(input, {
2317
configFile: false,
@@ -35,7 +29,7 @@ function testCase({
3529
};
3630
}
3731

38-
function testCaseNoChange(input: string): jasmine.ImplementationCallback {
32+
function testCaseNoChange(input: string) {
3933
return testCase({ input, expected: input });
4034
}
4135

0 commit comments

Comments
 (0)