mirror of
https://github.com/actions/setup-node.git
synced 2026-06-17 08:57:48 +00:00
Refactor github mock to use Context class
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
0251b05a6c
commit
88efa6885c
@ -1,49 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
// CJS shim for @actions/github (v9+ is ESM-only, incompatible with Jest's CJS resolver).
|
||||
// Replicates the Context class behaviour used by this repo: reads GITHUB_* env vars.
|
||||
const context = {
|
||||
get repo() {
|
||||
const [owner, repo] = (process.env['GITHUB_REPOSITORY'] || '/').split('/');
|
||||
return {owner, repo};
|
||||
},
|
||||
get eventName() {
|
||||
return process.env['GITHUB_EVENT_NAME'] || '';
|
||||
},
|
||||
get sha() {
|
||||
return process.env['GITHUB_SHA'] || '';
|
||||
},
|
||||
get ref() {
|
||||
return process.env['GITHUB_REF'] || '';
|
||||
},
|
||||
get workflow() {
|
||||
return process.env['GITHUB_WORKFLOW'] || '';
|
||||
},
|
||||
get action() {
|
||||
return process.env['GITHUB_ACTION'] || '';
|
||||
},
|
||||
get actor() {
|
||||
return process.env['GITHUB_ACTOR'] || '';
|
||||
},
|
||||
get job() {
|
||||
return process.env['GITHUB_JOB'] || '';
|
||||
},
|
||||
get runNumber() {
|
||||
return parseInt(process.env['GITHUB_RUN_NUMBER'] || '0', 10);
|
||||
},
|
||||
get runId() {
|
||||
return parseInt(process.env['GITHUB_RUN_ID'] || '0', 10);
|
||||
},
|
||||
get apiUrl() {
|
||||
return process.env['GITHUB_API_URL'] || 'https://api.github.com';
|
||||
},
|
||||
get serverUrl() {
|
||||
return process.env['GITHUB_SERVER_URL'] || 'https://github.com';
|
||||
},
|
||||
get graphqlUrl() {
|
||||
return process.env['GITHUB_GRAPHQL_URL'] || 'https://api.github.com/graphql';
|
||||
},
|
||||
payload: {}
|
||||
};
|
||||
|
||||
module.exports = {context};
|
||||
3
__tests__/mock/github-mock.ts
Normal file
3
__tests__/mock/github-mock.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import {Context} from '@actions/github/lib/context';
|
||||
|
||||
export const context = new Context();
|
||||
@ -9,6 +9,6 @@ module.exports = {
|
||||
},
|
||||
verbose: true,
|
||||
moduleNameMapper: {
|
||||
'^@actions/github$': '<rootDir>/__mocks__/@actions/github.js'
|
||||
'^@actions/github$': '<rootDir>/__tests__/mock/github-mock.ts'
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user