- make sure we reset env prior to the next test

- our new test requires history to be available
This commit is contained in:
Mike Penz
2025-07-13 16:02:14 +02:00
parent 0f359e3526
commit 8357bc6ec1
4 changed files with 27 additions and 5 deletions
+3
View File
@@ -16,6 +16,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 100
fetch-tags: true
- name: Set Node.js 20.x
uses: actions/setup-node@v4
+21 -4
View File
@@ -12,9 +12,21 @@ clear()
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory
test('missing values should result in failure', () => {
expect.assertions(1)
function resetEnv(): void {
process.env['INPUT_CONFIGURATION'] = ''
process.env['INPUT_OWNER'] = ''
process.env['INPUT_REPO'] = ''
process.env['INPUT_MODE'] = ''
process.env['INPUT_OFFLINEMODE'] = ''
process.env['INPUT_OUTPUTFILE'] = ''
process.env['INPUT_CACHE'] = ''
process.env['GITHUB_WORKSPACE'] = ''
process.env['INPUT_FROMTAG'] = ''
process.env['INPUT_TOTAG'] = ''
}
test('missing values should result in failure', () => {
resetEnv()
process.env['GITHUB_WORKSPACE'] = '.'
process.env['INPUT_OWNER'] = undefined
process.env['INPUT_CONFIGURATION'] = 'configs/configuration.json'
@@ -30,6 +42,7 @@ test('missing values should result in failure', () => {
})
test('complete input should succeed', () => {
resetEnv()
process.env['GITHUB_WORKSPACE'] = '.'
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
process.env['INPUT_OWNER'] = 'mikepenz'
@@ -48,8 +61,9 @@ test('complete input should succeed', () => {
})
test('should write result to file', () => {
resetEnv()
process.env['GITHUB_WORKSPACE'] = '.'
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
process.env['INPUT_CONFIGURATION'] = 'configs/configuration.json'
process.env['INPUT_OWNER'] = 'mikepenz'
process.env['INPUT_REPO'] = 'release-changelog-builder-action'
process.env['INPUT_FROMTAG'] = 'v0.3.0'
@@ -73,17 +87,19 @@ test('should write result to file', () => {
})
test('offline mode should work with commit mode', () => {
resetEnv()
// This test verifies that the offlineMode parameter is correctly passed to the configuration
// and that the OfflineRepository is used when offlineMode is enabled.
// Set up environment variables for the test
process.env['GITHUB_WORKSPACE'] = '.'
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
process.env['INPUT_CONFIGURATION'] = 'configs/configuration_commit.json'
process.env['INPUT_OWNER'] = 'mikepenz'
process.env['INPUT_REPO'] = 'release-changelog-builder-action'
process.env['INPUT_MODE'] = 'PR'
process.env['INPUT_OFFLINEMODE'] = 'true'
process.env['INPUT_OUTPUTFILE'] = 'test.md'
process.env['INPUT_CACHE'] = ''
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecSyncOptions = {
@@ -93,6 +109,7 @@ test('offline mode should work with commit mode', () => {
const result = cp.execFileSync('node', [ip], options).toString()
// should succeed
expect(result).toBeDefined()
console.log(result)
const readOutput = fs.readFileSync('test.md')
fs.unlinkSync('test.md')
+2 -1
View File
@@ -13,11 +13,12 @@
"lint": "eslint src/**/*.ts",
"package": "ncc build --source-map --license licenses.txt",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=default --reporters=jest-junit",
"test-main": "NODE_OPTIONS=--experimental-vm-modules jest __tests__/main.test.ts --reporters=default --reporters=jest-junit",
"test-github": "NODE_OPTIONS=--experimental-vm-modules jest __tests__/*.test.ts --reporters=default --reporters=jest-junit",
"test-gitea": "NODE_OPTIONS=--experimental-vm-modules jest __tests__/gitea/*.test.ts --reporters=default --reporters=jest-junit",
"test-demo": "NODE_OPTIONS=--experimental-vm-modules jest __tests__/demo/*.test.ts --reporters=default --reporters=jest-junit",
"test-offline": "NODE_OPTIONS=--experimental-vm-modules jest __tests__/offline/*.test.ts --reporters=default --reporters=jest-junit",
"all": "npm run build && npm run format && npm run lint && npm run package && npm run test-github"
"all": "npm run build && npm run format && npm run lint && npm run package && npm run test-main"
},
"repository": {
"type": "git",
+1
View File
@@ -10,6 +10,7 @@
"noImplicitThis": true,
"moduleResolution": "Node16",
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"isolatedModules": true,
"lib": [ "ESNext","ES2021.String", "dom"] /* Enable custom `ES2021.String` extension in typescript for `replaceAll` */
},
"exclude": ["node_modules", "__tests__/*.ts", "**/*.test.ts", "**/**/*.test.ts"],