Closed mxschmitt closed 1 year ago
@mxschmitt between all those notes I needed to sort and organize into a coherent review, I totally forgot to show my gratitude for taking on this huge task. My apologies. And: thank you!
Also:
request: { fetch: (await import('node-fetch')).default }
I just realized that you could also reinstate import fetch from "node-fetch"
(which I just noticed was reverted yesterday, and I assume the reason for it was that it was not mocked, but that should be easy via jest.mock('node-fetch')
, no?).
Hi,
yeah the reason why I changed it to a CJS import, was the following:
action-tmate on bump-deps [!?] via v18.17.1
❯ npm run test
> action-tmate@0.0.0 test
> GITHUB_EVENT_PATH= jest
FAIL src/index.test.js
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/Users/maxschmitt/Developer/action-tmate/node_modules/node-fetch/src/index.js:9
import http from 'node:http';
^^^^^^
SyntaxError: Cannot use import statement outside a module
7 | import * as tc from "@actions/tool-cache"
8 | import { Octokit } from "@octokit/rest"
> 9 | import fetch from "node-fetch"
| ^
10 |
11 | import { execShellCommand, getValidatedInput, getLinuxDistro, useSudoPrefix } from "./helpers"
12 |
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
at Object.require (src/index.js:9:1)
at Object.require (src/index.test.js:28:1)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 2.354 s
Ran all test suites.
action-tmate on bump-deps [!?] via v18.17.1 took 5s
Fixed it by adding babel-jest as a layer which transpiles everything to CJS. Ideally we should require the lib files instead of the src files inside the tests, but probably not a big deal here.
@mxschmitt unfortunately I get that TypeError: fetch is not a function
problem again: https://github.com/mxschmitt/action-tmate/actions/runs/6083513664/job/16503525646#step:5:18
So this now supersedes #173...
@mxschmitt I won't have time to tag and release it today, feel free to do that if you have the time.
@actions/tool-cache
v2.0.0 should not have any relevant breaking changes for us:@octokit/rest
v19/v20 should also not affect us:Tested it on the branch and it worked fine.
Fixes https://github.com/mxschmitt/action-tmate/issues/170