Skip to content

Tests broken by updating @action/* packages to ESM-only #55

Description

@muzimuzhi

Problem

See job run https://github.com/TeX-Live/setup-texlive-action/actions/runs/22686900577/job/65772177136

npx run-s test errors

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 7 ⎯⎯⎯⎯⎯⎯⎯

 FAIL   @setup-texlive-action/texlive  __tests__/releases.test.ts > LatestRelease > checkVersion > checks for latest version using the CTAN API
AssertionError: expected false to be true // Object.is equality

- Expected
+ Received

- true
+ false

 ❯ __tests__/releases.test.ts:33:29
     31|       const mock = doMock();
     32|       await expect(new Latest().checkVersion()).resolves.toBe(LATEST_V…
     33|       expect(mock.isDone()).toBe(true);
       |                             ^
     34|     });
     35| 

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/7]⎯

 FAIL   @setup-texlive-action/texlive  __tests__/releases.test.ts > LatestRelease > checkVersion > throws no exception
AssertionError: expected "spy" to be called with arguments: [ StringContaining "Failed to check" ]

Received: 

  1st spy call:

  [
-   StringContaining "Failed to check",
+   "Checking for latest version of TeX Live",
  ]

  2nd spy call:

  [
-   StringContaining "Failed to check",
+   "Latest version: 2026",
  ]


Number of calls: 2

 ❯ __tests__/releases.test.ts:38:25
     36|     it('throws no exception', async () => {
     37|       await expect(new Latest().checkVersion()).resolves.not.toThrow();
     38|       expect(core.info).toHaveBeenCalledWith(
       |                         ^
     39|         expect.stringContaining('Failed to check'),
     40|       );

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/7]⎯

 FAIL   @setup-texlive-action/texlive  __tests__/releases.test.ts > ReleaseData.setup > checks for the latest version if needed
AssertionError: expected false to be true // Object.is equality

- Expected
+ Received

- true
+ false

 ❯ __tests__/releases.test.ts:65:27
     63|     );
     64|     await expect(ReleaseData.setup()).resolves.not.toThrow();
     65|     expect(mock.isDone()).toBe(true);
       |                           ^
     66|   });
     67| });

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/7]⎯

 FAIL   @setup-texlive-action/texlive  __tests__/tlmgr/install.test.ts > tries to determine the TL name (2008) > using the CTAN API
 FAIL   @setup-texlive-action/texlive  __tests__/tlmgr/install.test.ts > tries to determine the TL name (2009) > using the CTAN API
 FAIL   @setup-texlive-action/texlive  __tests__/tlmgr/install.test.ts > tries to determine the TL name (2014) > using the CTAN API
 FAIL   @setup-texlive-action/texlive  __tests__/tlmgr/install.test.ts > tries to determine the TL name (2023) > using the CTAN API
AssertionError: expected false to be true // Object.is equality

- Expected
+ Received

- true
+ false

 ❯ __tests__/tlmgr/install.test.ts:109:27
    107|     );
    108|     expect(TlmgrInternals.prototype.exec).toHaveBeenCalledTimes(3);
    109|     expect(nock.isDone()).toBe(true);
       |                           ^
    110|   });
    111| });

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/7]⎯


 Test Files  2 failed | 21 passed (23)
      Tests  7 failed | 359 passed (366)
   Start at  20:03:50
   Duration  6.81s (transform 1.08s, setup 2.25s, collect 5.62s, tests 4.41s, environment 6ms, prepare 2.07s)


Error: AssertionError: expected false to be true // Object.is equality

- Expected
+ Received

- true
+ false

 ❯ __tests__/releases.test.ts:33:29



Error: AssertionError: expected "spy" to be called with arguments: [ StringContaining "Failed to check" ]

Received: 

  1st spy call:

  [
-   StringContaining "Failed to check",
+   "Checking for latest version of TeX Live",
  ]

  2nd spy call:

  [
-   StringContaining "Failed to check",
+   "Latest version: 2026",
  ]


Number of calls: 2

 ❯ __tests__/releases.test.ts:38:25



Error: AssertionError: expected false to be true // Object.is equality

- Expected
+ Received

- true
+ false

 ❯ __tests__/releases.test.ts:65:27



Error: AssertionError: expected false to be true // Object.is equality

- Expected
+ Received

- true
+ false

 ❯ __tests__/tlmgr/install.test.ts:109:27



Error: AssertionError: expected false to be true // Object.is equality

- Expected
+ Received

- true
+ false

 ❯ __tests__/tlmgr/install.test.ts:109:27



Error: AssertionError: expected false to be true // Object.is equality

- Expected
+ Received

- true
+ false

 ❯ __tests__/tlmgr/install.test.ts:109:27



Error: AssertionError: expected false to be true // Object.is equality

- Expected
+ Received

- true
+ false

 ❯ __tests__/tlmgr/install.test.ts:109:27

Analysis

nock used for mocking HTTP request is the culprit. From its doc,

Requests made by ES Modules are not intercepted

When an ES module imports request with a namespaced import like import * as http from "node:http", and the module is imported before nock, requests made by this module are not intercepted. You can fix this by telling Node to preload nock using the --import=nock CLI option or setting the NODE_OPTIONS=--import=nock environment variable.

I confirmed that setting NODE_OPTIONS=--import=nock does the trick:

diff --git a/package.json b/package.json
index f68c82a..9f6c1ca 100644
--- a/package.json
+++ b/package.json
@@ -15,7 +15,7 @@
     "licenses": "cd packages && rspack",
     "link-check": "markdown-link-check README.md",
     "lint": "cd packages && eslint .",
-    "test": "cd packages && vitest",
+    "test": "cd packages && NODE_OPTIONS=--import=nock vitest",
     "prepack": "run-p --aggregate-output -c build licenses",
     "preversion": "npm ci && npm run prepack",
     "version": "bash scripts/bump-version.sh",

See also the workflow run triggered by
99657ce (test: work around nock not intercepting requests made by ESM, 2026-03-17)

Plan

I will try if nock can be easily replaced with another mocking package which doesn't have such problem.

It seems the Node.js undici is one of the candidates. https://undici.nodejs.org/#/docs/best-practices/mocking-request

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions