Skip to content

Commit 4b4cecf

Browse files
committed
test: update tests to work with Jasmine version 4
These changes include fixes to tests, timeout and stop of architect to make tests work with Jasmine 4. One noticeable change that when we didn't stop architect through `run.stop()` this causes Bazel to timeout now. Example ``` -- Test timed out at 2022-03-24 12:07:07 UTC -- /private/var/tmp/_bazel_alanagius/5168427e57f204ca069c602aa7ed1931/sandbox/darwin-sandbox/398/execroot/angular_cli/bazel-out/darwin-fastbuild/bin/packages/angular_devkit/build_angular/build_angular_browser_test.sh.runfiles/angular_cli/packages/angular_devkit/build_angular/build_angular_browser_test.sh: line 424: 41835 Terminated: 15 "${node}" ${LAUNCHER_NODE_OPTIONS[@]+"${LAUNCHER_NODE_OPTIONS[@]}"} ${USER_NODE_OPTIONS[@]+"${USER_NODE_OPTIONS[@]}"} "${MAIN}" ${ARGS[@]+"${ARGS[@]}"} 0<&0 ```
1 parent b50efbb commit 4b4cecf

File tree

23 files changed

+174
-204
lines changed

23 files changed

+174
-204
lines changed

lib/bootstrap-local.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ const debugBuildTs = debug('ng:local:build:ts');
1616

1717
const child_process = require('child_process');
1818
const fs = require('fs');
19+
const os = require('os');
1920
const path = require('path');
20-
const temp = require('temp');
2121
const ts = require('typescript');
2222

23-
const tmpRoot = temp.mkdirSync('angular-devkit-');
23+
const tmpRoot = fs.mkdtempSync(path.join(fs.realpathSync(os.tmpdir()), 'angular-devkit-'));
2424

2525
debugLocal('starting bootstrap local');
2626

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@
202202
"stylus-loader": "6.2.0",
203203
"symbol-observable": "4.0.0",
204204
"tar": "^6.1.6",
205-
"temp": "^0.9.0",
206205
"terser": "5.12.1",
207206
"text-table": "0.2.0",
208207
"tree-kill": "1.2.2",

packages/angular_devkit/benchmark/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ jasmine_node_test(
6363
"@npm//pidtree",
6464
"@npm//pidusage",
6565
"@npm//source-map",
66-
"@npm//temp",
6766
"@npm//tree-kill",
6867
"@npm//yargs-parser",
6968
],

packages/angular_devkit/benchmark/src/main_spec.ts

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

9-
import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
9+
import { existsSync, mkdtempSync, readFileSync, realpathSync, unlinkSync, writeFileSync } from 'fs';
10+
import { tmpdir } from 'os';
1011
import { basename, dirname, join } from 'path';
1112
import { main } from './main';
1213

13-
// eslint-disable-next-line import/no-extraneous-dependencies
14-
const temp = require('temp');
15-
1614
// We only care about the write method in these mocks of NodeJS.WriteStream.
1715
class MockWriteStream {
1816
lines: string[] = [];
@@ -29,7 +27,7 @@ describe('benchmark binary', () => {
2927
const exitCodeOneScript = require.resolve(join(__dirname, './test/exit-code-one.js'));
3028
const benchmarkWatchScript = require.resolve(join(__dirname, './test/watch-test-cmd.js'));
3129
const watchTriggerScript = require.resolve(join(__dirname, './test/watch-test-script.js'));
32-
const outputFileRoot = temp.mkdirSync('benchmark-binary-spec-');
30+
const outputFileRoot = mkdtempSync(join(realpathSync(tmpdir()), 'benchmark-binary-spec-'));
3331
const outputFile = join(outputFileRoot, 'output.log');
3432
let stdout: MockWriteStream, stderr: MockWriteStream;
3533

packages/angular_devkit/build_angular/src/builders/browser/specs/build-optimizer_spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ describe('Browser Builder build optimizer', () => {
3030
it('fails if AOT is disabled', async () => {
3131
const overrides = { aot: false, buildOptimizer: true };
3232
const run = await architect.scheduleTarget(targetSpec, overrides);
33-
34-
try {
35-
await run.result;
36-
expect('THE ABOVE LINE SHOULD THROW').toBe('');
37-
} catch {}
33+
await expectAsync(run.result).toBeRejectedWithError();
34+
await run.stop();
3835
});
3936

4037
it('reduces bundle size', async () => {

packages/angular_devkit/build_angular/src/builders/browser/specs/cross-origin_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ describe('Browser Builder crossOrigin', () => {
9999
const fileName = join(normalize(output.outputPath), 'runtime.js');
100100
const content = virtualFs.fileBufferToString(await host.read(normalize(fileName)).toPromise());
101101
expect(content).toContain('script.crossOrigin = "use-credentials"');
102+
await run.stop();
102103
});
103104
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ describe('Browser Builder index HTML processing', () => {
156156
`<script src="polyfills.js" type="module"></script>` +
157157
`<script src="vendor.js" type="module"></script><script src="main.js" type="module"></script></body></html>`,
158158
);
159+
await run.stop();
159160
});
160161

161162
it('uses the output value from the index option longform', async () => {
@@ -202,6 +203,7 @@ describe('Browser Builder index HTML processing', () => {
202203
`<script src="polyfills.js" type="module"></script>` +
203204
`<script src="vendor.js" type="module"></script><script src="main.js" type="module"></script></body></html>`,
204205
);
206+
await run.stop();
205207
});
206208

207209
it('creates subdirectories for output value from the index option longform', async () => {
@@ -248,5 +250,6 @@ describe('Browser Builder index HTML processing', () => {
248250
`<script src="polyfills.js" type="module"></script>` +
249251
`<script src="vendor.js" type="module"></script><script src="main.js" type="module"></script></body></html>`,
250252
);
253+
await run.stop();
251254
});
252255
});

packages/angular_devkit/build_angular/src/builders/browser/specs/lazy-module_spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('Browser Builder lazy modules', () => {
6565

6666
const { files } = await browserBuild(architect, host, target, { aot: true });
6767
const data = await files['src_app_lazy_lazy_module_ts.js'];
68-
expect(data).not.toBeUndefined('Lazy module output bundle does not exist');
68+
expect(data).not.toBeUndefined();
6969
expect(data).toContain('LazyModule.ɵmod');
7070
});
7171
});
@@ -85,7 +85,8 @@ describe('Browser Builder lazy modules', () => {
8585
const run = await architect.scheduleTarget(target, {}, { logger });
8686
const output = await run.result;
8787
expect(output.success).toBe(false);
88-
expect(hasMissingModuleError(logs.join())).toBe(true, 'Should show missing module error');
88+
expect(hasMissingModuleError(logs.join())).toBeTrue();
89+
await run.stop();
8990
});
9091

9192
it('should show error when lazy route is invalid on watch mode AOT', async () => {
@@ -98,7 +99,7 @@ describe('Browser Builder lazy modules', () => {
9899
const run = await architect.scheduleTarget(target, overrides);
99100
await run.output
100101
.pipe(
101-
debounceTime(3000),
102+
debounceTime(1500),
102103
tap((buildEvent) => {
103104
buildNumber++;
104105
switch (buildNumber) {

packages/angular_devkit/build_angular/src/builders/browser/specs/output-path_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe('Browser Builder output path', () => {
6565

6666
expect(await host.exists(join(host.root(), 'dist')).toPromise()).toBe(false);
6767
expect(await host.exists(join(host.root(), 'src-link')).toPromise()).toBe(true);
68+
await run.stop();
6869
});
6970

7071
it('does not allow output path to be project root', async () => {

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
*/
88

99
import { Architect } from '@angular-devkit/architect';
10-
import { debounceTime, take, tap } from 'rxjs/operators';
10+
import { debounceTime, take, tap, timeout } from 'rxjs/operators';
1111
import { createArchitect, host } from '../../../testing/test-utils';
12+
import { BUILD_TIMEOUT } from '../index';
1213

1314
describe('Browser Builder poll', () => {
1415
const target = { project: 'app', target: 'build' };
@@ -21,13 +22,14 @@ describe('Browser Builder poll', () => {
2122
afterEach(async () => host.restore().toPromise());
2223

2324
it('works', async () => {
24-
const overrides = { watch: true, poll: 10000 };
25+
const overrides = { watch: true, poll: 4000 };
2526
const intervals: number[] = [];
2627
let startTime: number | undefined;
2728

2829
const run = await architect.scheduleTarget(target, overrides);
2930
await run.output
3031
.pipe(
32+
timeout(BUILD_TIMEOUT),
3133
// Debounce 1s, otherwise changes are too close together and polling doesn't work.
3234
debounceTime(1000),
3335
tap((buildEvent) => {
@@ -46,5 +48,7 @@ describe('Browser Builder poll', () => {
4648
const median = intervals[Math.trunc(intervals.length / 2)];
4749
expect(median).toBeGreaterThan(3000);
4850
expect(median).toBeLessThan(12000);
51+
52+
await run.stop();
4953
});
5054
});

0 commit comments

Comments
 (0)