node icon indicating copy to clipboard operation
node copied to clipboard

test_runner: fix delete test file cause dependency file change not rerun the tests

Open jakecastelli opened this issue 1 year ago • 1 comments
trafficstars

There is an edge case left from https://github.com/nodejs/node/pull/53114

Reproduce step:

// create dependency index.js
export const a = 1;
export const b = 2;
export const c = 3;
// create test-a.mjs
import { a } from "./index.mjs";

import { test } from "node:test";
import assert from "node:assert";

test("test One", () => {
  assert.equal(a, 1);
});
// create test-b.mjs
import { a, b } from "./index.mjs";

import { test } from "node:test";
import assert from "node:assert";

test("test Two", () => {
  assert.equal(a, 1);
  assert.equal(b, 2);
});
// create test-c.mjs
import { a, b, c } from "./index.mjs";

import { test } from "node:test";
import assert from "node:assert";

test("test Three", () => {
  assert.equal(a, 1);
  assert.equal(b, 2);
  assert.equal(c, 3);
});

node --watch --test

# now delete test-a.mjs
# then make any change to index.mjs e.g. change const a = 1 to const a = 2

You would observe that test-b.mjs and test-c.mjs are not being rerun. The expected behaviour should be test-b.mjs, test-c.mjs being rerun and failed (since assert.strictEqual(a, 1) is not correct anymore).

Change explain:

When a watched test file is being deleted, the test runner will rerun the test(s) and because the test file is no longer there but the dependencyOwners wouldn't be able to know it, so it failed in silence. Since a test file is being deleted, we don't need to rerun anything so we can just safely return.

notes:

The test is quite identical to test/parallel/test-runner-watch-mode.mjs but with a more complicated setup, I am thinking to spend some time to see how I can refactor the test so we can write more complicated test cases in the future, I am committed and would like to do a separate PR for it.

Ref: https://github.com/nodejs/node/pull/53114

jakecastelli avatar Jun 21 '24 16:06 jakecastelli

Review requested:

  • [ ] @nodejs/test_runner

nodejs-github-bot avatar Jun 21 '24 16:06 nodejs-github-bot

maybe we can get CI started again? 👀

jakecastelli avatar Jul 07 '24 08:07 jakecastelli

CI: https://ci.nodejs.org/job/node-test-pull-request/60140/

nodejs-github-bot avatar Jul 07 '24 15:07 nodejs-github-bot

Haven't got back from @benjamingr yet on https://github.com/nodejs/node/pull/53533#discussion_r1667749702, shall we land this bug fix first and I can try to create a follow up PR to improve it.

jakecastelli avatar Aug 06 '24 13:08 jakecastelli

CI: https://ci.nodejs.org/job/node-test-pull-request/60907/

nodejs-github-bot avatar Aug 06 '24 13:08 nodejs-github-bot

hall we land this bug fix first and I can try to create a follow up PR to improve it.

SGTM

benjamingr avatar Aug 06 '24 19:08 benjamingr

CI: https://ci.nodejs.org/job/node-test-pull-request/60917/

nodejs-github-bot avatar Aug 07 '24 01:08 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/60920/

nodejs-github-bot avatar Aug 07 '24 05:08 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/60929/

nodejs-github-bot avatar Aug 07 '24 10:08 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/60934/

nodejs-github-bot avatar Aug 07 '24 12:08 nodejs-github-bot

I figured out the watch capability is limited in AIX which caused the test in CI on that platform to fail.

jakecastelli avatar Aug 08 '24 03:08 jakecastelli

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 87.10%. Comparing base (e0634f5) to head (b1e06fc). Report is 459 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/test_runner/runner.js 0.00% 6 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #53533      +/-   ##
==========================================
- Coverage   87.10%   87.10%   -0.01%     
==========================================
  Files         647      647              
  Lines      181739   181759      +20     
  Branches    34887    34889       +2     
==========================================
+ Hits       158310   158323      +13     
- Misses      16738    16740       +2     
- Partials     6691     6696       +5     
Files with missing lines Coverage Δ
lib/internal/test_runner/runner.js 84.86% <0.00%> (-0.69%) :arrow_down:

... and 27 files with indirect coverage changes

codecov[bot] avatar Aug 08 '24 05:08 codecov[bot]

CI: https://ci.nodejs.org/job/node-test-pull-request/60973/

nodejs-github-bot avatar Aug 08 '24 07:08 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/60975/

nodejs-github-bot avatar Aug 08 '24 10:08 nodejs-github-bot

CI: https://ci.nodejs.org/job/node-test-pull-request/60976/

nodejs-github-bot avatar Aug 08 '24 11:08 nodejs-github-bot

Green CI now 🥳 would appreciate someone can take a look again and give a green tick so this PR is able to land (my latest change was skipping the test on AIX platform as the watch capability is restricted)

jakecastelli avatar Aug 08 '24 12:08 jakecastelli

@mcollina do you mind taking a quick look 🙏 as you recently did some work in this area as well

jakecastelli avatar Aug 12 '24 01:08 jakecastelli

Landed in 1212eca1fcdfdfca83135bf3d878743851b9d3b5

nodejs-github-bot avatar Aug 14 '24 15:08 nodejs-github-bot