Skip to content

Commit

Permalink
refactor: replace custom promise-based setTimeout with native Node.js…
Browse files Browse the repository at this point in the history
… setTimeout

In this commit, the custom implementation of a promise-based setTimeout function has been replaced with the native Node.js setTimeout function, which now returns a promise.

(cherry picked from commit 4b95aec)
  • Loading branch information
alan-agius4 committed Jun 11, 2024
1 parent 3a1bf5c commit 9320b65
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* found in the LICENSE file at https://angular.dev/license
*/

import { setTimeout } from 'node:timers/promises';
import { tags } from '@angular-devkit/core';
import { last, tap } from 'rxjs';
import { promisify } from 'util';
import { execute } from '../../index';
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';

Expand All @@ -19,7 +19,6 @@ import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
// are subsequently written to disk. For more information, see
// https://github.com/karma-runner/karma-coverage/blob/32acafa90ed621abd1df730edb44ae55a4009c2c/lib/reporter.js#L221

const setTimeoutPromise = promisify(setTimeout);
const coveragePath = 'coverage/lcov.info';

describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
Expand All @@ -36,7 +35,7 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();

await setTimeoutPromise(1000);
await setTimeout(1000);
harness.expectFile(coveragePath).toExist();
});

Expand Down Expand Up @@ -111,7 +110,7 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();

await setTimeoutPromise(1000);
await setTimeout(1000);

harness
.expectFile('coverage/app.component.ts.html')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* 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 { promisify } from 'util';
import { setTimeout } from 'node:timers/promises';
import { execute } from '../../index';
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';

Expand All @@ -17,7 +16,6 @@ import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
// are subsequently written to disk. For more information, see
// https://github.com/karma-runner/karma-coverage/blob/32acafa90ed621abd1df730edb44ae55a4009c2c/lib/reporter.js#L221

const setTimeoutPromise = promisify(setTimeout);
const coveragePath = 'coverage/lcov.info';

describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
Expand All @@ -33,7 +31,7 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {

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

await setTimeoutPromise(1000);
await setTimeout(1000);
harness.expectFile(coveragePath).content.not.toContain('app.component.ts');
});

Expand All @@ -48,7 +46,7 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {

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

await setTimeoutPromise(1000);
await setTimeout(1000);
harness.expectFile(coveragePath).content.not.toContain('app.component.ts');
});

Expand All @@ -62,7 +60,7 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {

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

await setTimeoutPromise(1000);
await setTimeout(1000);
harness.expectFile(coveragePath).content.toContain('app.component.ts');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/

import { promisify } from 'util';
import { setTimeout } from 'node:timers/promises';
import { execute } from '../../index';
import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';

Expand All @@ -17,7 +17,6 @@ import { BASE_OPTIONS, KARMA_BUILDER_INFO, describeBuilder } from '../setup';
// are subsequently written to disk. For more information, see
// https://github.com/karma-runner/karma-coverage/blob/32acafa90ed621abd1df730edb44ae55a4009c2c/lib/reporter.js#L221

const setTimeoutPromise = promisify(setTimeout);
const coveragePath = 'coverage/lcov.info';

describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
Expand All @@ -31,7 +30,7 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();

await setTimeoutPromise(1000);
await setTimeout(1000);
harness.expectFile(coveragePath).toExist();
});

Expand All @@ -45,7 +44,7 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {

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

await setTimeoutPromise(1000);
await setTimeout(1000);
harness.expectFile(coveragePath).toNotExist();
});

Expand All @@ -58,7 +57,7 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {

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

await setTimeoutPromise(1000);
await setTimeout(1000);
harness.expectFile(coveragePath).toNotExist();
});

Expand All @@ -73,7 +72,7 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
'./src/app/app.component.ts': `
import { Component } from '@angular/core';
import { title } from 'my-lib';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
Expand Down Expand Up @@ -105,7 +104,7 @@ describeBuilder(execute, KARMA_BUILDER_INFO, (harness) => {
const { result } = await harness.executeOnce();
expect(result?.success).toBeTrue();

await setTimeoutPromise(1000);
await setTimeout(1000);
harness.expectFile(coveragePath).content.not.toContain('my-lib');
});
});
Expand Down

0 comments on commit 9320b65

Please sign in to comment.