mirror of
https://github.com/hashicorp/vault-action.git
synced 2025-11-07 15:16:56 +00:00
wip: replace jest with vitest
This commit is contained in:
parent
b379e88781
commit
fcac78057e
22 changed files with 2182 additions and 78 deletions
3
dist/package.json
vendored
Normal file
3
dist/package.json
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"type": "module"
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
jest.mock('@actions/core');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
jest.mock('@actions/core/lib/command');
|
|
||||||
|
vi.mock('@actions/core');
|
||||||
|
vi.mock('@actions/core/lib/command');
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
|
|
@ -102,7 +104,7 @@ describe('authenticate with approle', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('method', expect.anything())
|
.calledWith('method', expect.anything())
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
jest.mock('@actions/core');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
jest.mock('@actions/core/lib/command');
|
|
||||||
|
vi.mock('@actions/core');
|
||||||
|
vi.mock('@actions/core/lib/command');
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
|
|
@ -107,7 +109,7 @@ describe('integration', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
verbose: true
|
|
||||||
};
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
jest.mock('@actions/core');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
jest.mock('@actions/core/lib/command');
|
|
||||||
|
vi.mock('@actions/core');
|
||||||
|
vi.mock('@actions/core/lib/command');
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import rsasign from 'jsrsasign';
|
import rsasign from 'jsrsasign';
|
||||||
import {
|
import {
|
||||||
privateRsaKey,
|
privateRsaKey,
|
||||||
privateRsaKeyBase64,
|
privateRsaKeyBase64,
|
||||||
publicRsaKey
|
publicRsaKey
|
||||||
} from './rsa_keys.js');
|
} from './rsa_keys.js';
|
||||||
|
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
import { when } from 'jest-when'
|
import { when } from 'jest-when'
|
||||||
|
|
@ -139,7 +141,7 @@ describe('jwt auth', () => {
|
||||||
|
|
||||||
describe('authenticate with private key', () => {
|
describe('authenticate with private key', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
|
|
@ -189,7 +191,7 @@ describe('jwt auth', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
jest.mock('@actions/core');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
jest.mock('@actions/core/lib/command');
|
|
||||||
|
vi.mock('@actions/core');
|
||||||
|
vi.mock('@actions/core/lib/command');
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
|
|
|
||||||
8
integrationTests/basic/vitest.config.js
Normal file
8
integrationTests/basic/vitest.config.js
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { defineConfig } from 'vitest/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
// required to make jest-when work with vitest
|
||||||
|
globals: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { describe, test, expect } from 'vitest';
|
||||||
|
|
||||||
describe('e2e-tls', () => {
|
describe('e2e-tls', () => {
|
||||||
it('verify', () => {
|
it('verify', () => {
|
||||||
expect(process.env.SECRET).toBe("SUPERSECRET");
|
expect(process.env.SECRET).toBe("SUPERSECRET");
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { describe, test, expect } from 'vitest';
|
||||||
|
|
||||||
describe('e2e', () => {
|
describe('e2e', () => {
|
||||||
it('verify', () => {
|
it('verify', () => {
|
||||||
expect(process.env.SECRET).toBe("SUPERSECRET");
|
expect(process.env.SECRET).toBe("SUPERSECRET");
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
verbose: true
|
|
||||||
};
|
|
||||||
8
integrationTests/e2e/vitest.config.js
Normal file
8
integrationTests/e2e/vitest.config.js
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { defineConfig } from 'vitest/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
// required to make jest-when work with vitest
|
||||||
|
globals: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
jest.mock('@actions/core');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
jest.mock('@actions/core/lib/command');
|
|
||||||
|
vi.mock('@actions/core');
|
||||||
|
vi.mock('@actions/core/lib/command');
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
|
|
@ -41,7 +43,7 @@ describe('integration', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
|
|
@ -238,7 +240,7 @@ describe('authenticate with approle', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('method', expect.anything())
|
.calledWith('method', expect.anything())
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
verbose: true
|
|
||||||
};
|
|
||||||
8
integrationTests/enterprise/vitest.config.js
Normal file
8
integrationTests/enterprise/vitest.config.js
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { defineConfig } from 'vitest/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
// required to make jest-when work with vitest
|
||||||
|
globals: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
// module.exports = {
|
|
||||||
// transform: {},
|
|
||||||
// testPathIgnorePatterns: ['/node_modules/', '<rootDir>/integrationTests/'],
|
|
||||||
// };
|
|
||||||
|
|
||||||
export default {
|
|
||||||
transform: {},
|
|
||||||
testPathIgnorePatterns: ['/node_modules/', '<rootDir>/integrationTests/'],
|
|
||||||
};
|
|
||||||
2081
package-lock.json
generated
2081
package-lock.json
generated
File diff suppressed because it is too large
Load diff
13
package.json
13
package.json
|
|
@ -6,11 +6,11 @@
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build src/entry.js -o dist",
|
"build": "ncc build src/entry.js -o dist",
|
||||||
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest",
|
"test": "vitest run retries",
|
||||||
"test:integration:basic": "jest -c integrationTests/basic/jest.config.js",
|
"test:integration:basic": "vitest run -c integrationTests/basic/vitest.config.js",
|
||||||
"test:integration:enterprise": "jest -c integrationTests/enterprise/jest.config.js",
|
"test:integration:enterprise": "vitest run -c integrationTests/enterprise/vitest.config.js",
|
||||||
"test:integration:e2e": "jest -c integrationTests/e2e/jest.config.js",
|
"test:integration:e2e": "vitest run -c integrationTests/e2e/vitest.config.js",
|
||||||
"test:integration:e2e-tls": "jest -c integrationTests/e2e-tls/jest.config.js"
|
"test:integration:e2e-tls": "vitest run -c integrationTests/e2e-tls/vitest.config.js"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src/**/*",
|
"src/**/*",
|
||||||
|
|
@ -47,6 +47,7 @@
|
||||||
"@vercel/ncc": "^0.38.1",
|
"@vercel/ncc": "^0.38.1",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-when": "^3.6.0",
|
"jest-when": "^3.6.0",
|
||||||
"mock-http-server": "^1.4.5"
|
"mock-http-server": "^1.4.5",
|
||||||
|
"vitest": "^1.3.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -111,8 +111,7 @@ async function exportSecrets() {
|
||||||
|
|
||||||
for (const line of value.replace(/\r/g, '').split('\n')) {
|
for (const line of value.replace(/\r/g, '').split('\n')) {
|
||||||
if (line.length > 0) {
|
if (line.length > 0) {
|
||||||
// core.setSecret(line);
|
core.setSecret(line);
|
||||||
core.setOutput(line);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (exportEnv) {
|
if (exportEnv) {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { jest } from '@jest/globals';
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
|
|
||||||
jest.mock('got');
|
vi.mock('got');
|
||||||
jest.mock('@actions/core');
|
vi.mock('@actions/core');
|
||||||
jest.mock('@actions/core/lib/command');
|
vi.mock('@actions/core/lib/command');
|
||||||
|
|
||||||
import * as command from '@actions/core/lib/command';
|
import * as command from '@actions/core/lib/command';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
|
@ -134,7 +134,7 @@ describe('parseHeaders', () => {
|
||||||
|
|
||||||
describe('exportSecrets', () => {
|
describe('exportSecrets', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('url', expect.anything())
|
.calledWith('url', expect.anything())
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import { jest } from '@jest/globals';
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
|
|
||||||
jest.mock('got');
|
vi.mock('got');
|
||||||
jest.mock('@actions/core');
|
vi.mock('@actions/core');
|
||||||
jest.mock('@actions/core/lib/command');
|
vi.mock('@actions/core/lib/command');
|
||||||
jest.mock('fs', () => ({
|
vi.mock('fs', () => ({
|
||||||
stat: jest.fn().mockResolvedValue(null),
|
stat: vi.fn().mockResolvedValue(null),
|
||||||
promises: {
|
promises: {
|
||||||
access: jest.fn().mockResolvedValue(null),
|
access: vi.fn().mockResolvedValue(null),
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ function mockInput(name, key) {
|
||||||
|
|
||||||
function mockApiResponse() {
|
function mockApiResponse() {
|
||||||
const response = { body: { auth: { client_token: testToken, renewable: true, policies: [], accessor: "accessor" } } }
|
const response = { body: { auth: { client_token: testToken, renewable: true, policies: [], accessor: "accessor" } } }
|
||||||
got.post = jest.fn()
|
got.post = vi.fn()
|
||||||
got.post.mockReturnValue(response)
|
got.post.mockReturnValue(response)
|
||||||
}
|
}
|
||||||
const testToken = "testoken";
|
const testToken = "testoken";
|
||||||
|
|
@ -34,7 +34,7 @@ const testToken = "testoken";
|
||||||
describe("test retrival for token", () => {
|
describe("test retrival for token", () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("test retrival with approle", async () => {
|
it("test retrival with approle", async () => {
|
||||||
|
|
@ -75,7 +75,7 @@ describe("test retrival for token", () => {
|
||||||
mockInput("kubernetesTokenPath", testTokenPath)
|
mockInput("kubernetesTokenPath", testTokenPath)
|
||||||
mockInput("role", testRole)
|
mockInput("role", testRole)
|
||||||
mockInput("path", testPath)
|
mockInput("path", testPath)
|
||||||
fs.readFileSync = jest.fn()
|
fs.readFileSync = vi.fn()
|
||||||
fs.readFileSync.mockReturnValueOnce(jwtToken)
|
fs.readFileSync.mockReturnValueOnce(jwtToken)
|
||||||
const token = await retrieveToken(method, got)
|
const token = await retrieveToken(method, got)
|
||||||
expect(token).toEqual(testToken)
|
expect(token).toEqual(testToken)
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,19 @@
|
||||||
jest.mock('@actions/core');
|
import { vi, describe, test, expect } from 'vitest';
|
||||||
|
|
||||||
|
vi.mock('@actions/core');
|
||||||
|
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as ServerMock from 'mock-http-server';
|
import ServerMock from 'mock-http-server';
|
||||||
import exportSecrets from './action.js';
|
import { exportSecrets } from './action.js';
|
||||||
import { when } from 'jest-when'
|
import { when } from 'jest-when';
|
||||||
|
|
||||||
describe('exportSecrets retries', () => {
|
describe('exportSecrets retries', () => {
|
||||||
var server = new ServerMock({ host: "127.0.0.1", port: 0 });
|
var server = new ServerMock({ host: "127.0.0.1", port: 0 });
|
||||||
var calls = 0;
|
var calls = 0;
|
||||||
|
|
||||||
beforeEach((done) => {
|
beforeEach(() => new Promise(done => {
|
||||||
calls = 0;
|
calls = 0;
|
||||||
jest.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
|
||||||
when(core.getInput)
|
when(core.getInput)
|
||||||
.calledWith('token', expect.anything())
|
.calledWith('token', expect.anything())
|
||||||
|
|
@ -28,11 +30,11 @@ describe('exportSecrets retries', () => {
|
||||||
.mockReturnValueOnce('http://127.0.0.1:' + server.getHttpPort());
|
.mockReturnValueOnce('http://127.0.0.1:' + server.getHttpPort());
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
|
|
||||||
afterEach((done) => {
|
afterEach(() => new Promise(done => {
|
||||||
server.stop(done);
|
server.stop(done);
|
||||||
});
|
}));
|
||||||
|
|
||||||
function mockStatusCodes(statusCodes) {
|
function mockStatusCodes(statusCodes) {
|
||||||
server.on({
|
server.on({
|
||||||
|
|
@ -51,19 +53,19 @@ describe('exportSecrets retries', () => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it('retries on 412 status code', (done) => {
|
it('retries on 412 status code', () => new Promise(done => {
|
||||||
mockStatusCodes([412, 200])
|
mockStatusCodes([412, 200])
|
||||||
exportSecrets().then(() => {
|
exportSecrets().then(() => {
|
||||||
expect(calls).toEqual(2);
|
expect(calls).toEqual(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
|
|
||||||
it('retries on 500 status code', (done) => {
|
it('retries on 500 status code', () => new Promise(done => {
|
||||||
mockStatusCodes([500, 200])
|
mockStatusCodes([500, 200])
|
||||||
exportSecrets().then(() => {
|
exportSecrets().then(() => {
|
||||||
expect(calls).toEqual(2);
|
expect(calls).toEqual(2);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
12
vitest.config.js
Normal file
12
vitest.config.js
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { defineConfig, configDefaults } from 'vitest/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
// required to make jest-when work with vitest
|
||||||
|
globals: true,
|
||||||
|
exclude:[
|
||||||
|
...configDefaults.exclude,
|
||||||
|
'**/integrationTests/**'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
})
|
||||||
Loading…
Reference in a new issue