nock
nock copied to clipboard
Basic usage not working in Github Actions, but works locally
Please avoid duplicates
- [X] I checked all open bugs and none of them matched my problem.
Reproducible test case
https://www.typescriptlang.org/play?#code/CYUwzgxgTglgRiAFAcgMIBsYgHYBcAEUIAjgK7i6ICU+A7jLgBb4Sli4D2AtvoyAIagoyADT5q+ALwA+fAG8AUPnz8AZrhBQAovwiNEEmfmwcIAawB0EdAOwBBdOmpUA3AqX4N7FADV+mYBVgYAYYDmx-XgEhURUwAE9sCHEaI0VlZRNzFEZcXAAHMAAuAHoS9FN-Rg52ZCoPDPwLAHMQSmQS-P4mOoaMizJNeMRcKHIaMvwASWaTIjB8Qah4-HZYbGa+5QsifPRhgCYABiOxOU8KIvxkedJ0XGR8AF9XPohw9hZMHAJJYxBaPgMFg8IgAAoAJQA8gANACaAH0ABJQgDKABUxHYwVMEQBpLRw16Nd7YT6sdjcJHRTQLP7pRrXLy4AC0fEEmmQV2QzJZADd-ORRH0nm43h8CDBsPlSL98ABtZAAcS06NiHS6PTEyCW8UkaylzXVcA4wHiyAAum4SRL8CA+T8pPhWrhsVMld0Afx4mCoBwAB7xLQO0FSmW4YkZUmfeb5D4gJ38Wj8BhfEG4HYkcjee0-MQUzhcakcqBgSPKED+-IgCCUWPxqgWTio0YwWtaMj+RAMxoms1XABSqKhADkLAaNjBVMNzszubd7o8XiItlES8V5KvlMhSRo8CzcPFq1zrvx8ns290wtgSgArMDhYWMjI8ihsmnCbm8gXoIUr59PP+jLsN0bCoKaIBXMcpwipGLwuEAA
Nock Version
13.2.9
Node Version
14.17.0
TypeScript Version
4.7.4
{
"compilerOptions": {
"module": "commonjs",
"resolveJsonModule": true,
"noUnusedLocals": true,
"strictNullChecks": false,
"target": "es2017",
"moduleResolution": "node",
"sourceMap": true,
"inlineSources": true,
"sourceRoot": "/",
"rootDir": "./",
"baseUrl": ".",
"outDir": "dist",
"declaration": true,
"paths": {
"src/*": ["src/*"]
}
},
"include": ["./src/**/*"],
"exclude": ["node_modules"]
}
What happened?
A very basic test works locally, but fails every time in Github Actions with this error message:
FAIL src/CustomHeader.test.ts
● Test suite failed to run
TypeError: Cannot set property request of [object Object] which has only a getter
at node_modules/nock/lib/common.js:95:20
at Array.forEach (<anonymous>)
at Object.overrideRequests (node_modules/nock/lib/common.js:71:22)
at activate (node_modules/nock/lib/intercept.js:373:10)
at Object.setup (node_modules/nock/lib/back.js:115:5)
at Function.Object.<anonymous>.Back.setMode (node_modules/nock/lib/back.js:330:9)
at Object.<anonymous> (node_modules/nock/index.js:52:8)
The relevant part of the test. And again, this works locally, but fails in Github Actions:
describe('Client request() with custom header', () => {
afterEach(() => nock.cleanAll());
test('Valid additional header', async () => {
nock('https://localhost')
.get('/path')
.query(true) // Ignores query string
.reply(200, { test: 'result' });
const client = new Client(PROXY_HOST, API_KEY);
const customHeaders = {
'test-header': 'test-value',
};
const input = ['GET', '/path', 'query=string', 'body'];
const event = getAPIGatewayProxyEvent(input);
const response = await client.request(event, customHeaders);
expect(response).toStrictEqual({
body: JSON.stringify({ test: 'result' }),
headers: {
'content-type': 'application/json',
'test-header': 'test-value',
},
statusCode: 200,
});
});
Would you be interested in contributing a fix?
- [ ] yes
So.... no results on this? Willing to fix this if given pointers.
@Torniojaws Does this issue persist?
From the stack trace you provided, it seems like another library overrides the get
or request
(or the http
module itself) before Nock does.
Can you please create a repo that reproduces the problem?
stale. Nock tests run in GitHub Actions, so without further information, we can't help. Feel free to reopen with reproduction.