Skip to content

Commit 8357bc6

Browse files
committed
- make sure we reset env prior to the next test
- our new test requires history to be available
1 parent 0f359e3 commit 8357bc6

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ jobs:
1616
steps:
1717
- name: Checkout
1818
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 100
21+
fetch-tags: true
1922

2023
- name: Set Node.js 20.x
2124
uses: actions/setup-node@v4

__tests__/main.test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,21 @@ clear()
1212
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
1313
const __dirname = path.dirname(__filename); // get the name of the directory
1414

15-
test('missing values should result in failure', () => {
16-
expect.assertions(1)
15+
function resetEnv(): void {
16+
process.env['INPUT_CONFIGURATION'] = ''
17+
process.env['INPUT_OWNER'] = ''
18+
process.env['INPUT_REPO'] = ''
19+
process.env['INPUT_MODE'] = ''
20+
process.env['INPUT_OFFLINEMODE'] = ''
21+
process.env['INPUT_OUTPUTFILE'] = ''
22+
process.env['INPUT_CACHE'] = ''
23+
process.env['GITHUB_WORKSPACE'] = ''
24+
process.env['INPUT_FROMTAG'] = ''
25+
process.env['INPUT_TOTAG'] = ''
26+
}
1727

28+
test('missing values should result in failure', () => {
29+
resetEnv()
1830
process.env['GITHUB_WORKSPACE'] = '.'
1931
process.env['INPUT_OWNER'] = undefined
2032
process.env['INPUT_CONFIGURATION'] = 'configs/configuration.json'
@@ -30,6 +42,7 @@ test('missing values should result in failure', () => {
3042
})
3143

3244
test('complete input should succeed', () => {
45+
resetEnv()
3346
process.env['GITHUB_WORKSPACE'] = '.'
3447
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
3548
process.env['INPUT_OWNER'] = 'mikepenz'
@@ -48,8 +61,9 @@ test('complete input should succeed', () => {
4861
})
4962

5063
test('should write result to file', () => {
64+
resetEnv()
5165
process.env['GITHUB_WORKSPACE'] = '.'
52-
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
66+
process.env['INPUT_CONFIGURATION'] = 'configs/configuration.json'
5367
process.env['INPUT_OWNER'] = 'mikepenz'
5468
process.env['INPUT_REPO'] = 'release-changelog-builder-action'
5569
process.env['INPUT_FROMTAG'] = 'v0.3.0'
@@ -73,17 +87,19 @@ test('should write result to file', () => {
7387
})
7488

7589
test('offline mode should work with commit mode', () => {
90+
resetEnv()
7691
// This test verifies that the offlineMode parameter is correctly passed to the configuration
7792
// and that the OfflineRepository is used when offlineMode is enabled.
7893

7994
// Set up environment variables for the test
8095
process.env['GITHUB_WORKSPACE'] = '.'
81-
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
96+
process.env['INPUT_CONFIGURATION'] = 'configs/configuration_commit.json'
8297
process.env['INPUT_OWNER'] = 'mikepenz'
8398
process.env['INPUT_REPO'] = 'release-changelog-builder-action'
8499
process.env['INPUT_MODE'] = 'PR'
85100
process.env['INPUT_OFFLINEMODE'] = 'true'
86101
process.env['INPUT_OUTPUTFILE'] = 'test.md'
102+
process.env['INPUT_CACHE'] = ''
87103

88104
const ip = path.join(__dirname, '..', 'lib', 'main.js')
89105
const options: cp.ExecSyncOptions = {
@@ -93,6 +109,7 @@ test('offline mode should work with commit mode', () => {
93109
const result = cp.execFileSync('node', [ip], options).toString()
94110
// should succeed
95111
expect(result).toBeDefined()
112+
console.log(result)
96113

97114
const readOutput = fs.readFileSync('test.md')
98115
fs.unlinkSync('test.md')

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
"lint": "eslint src/**/*.ts",
1414
"package": "ncc build --source-map --license licenses.txt",
1515
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=default --reporters=jest-junit",
16+
"test-main": "NODE_OPTIONS=--experimental-vm-modules jest __tests__/main.test.ts --reporters=default --reporters=jest-junit",
1617
"test-github": "NODE_OPTIONS=--experimental-vm-modules jest __tests__/*.test.ts --reporters=default --reporters=jest-junit",
1718
"test-gitea": "NODE_OPTIONS=--experimental-vm-modules jest __tests__/gitea/*.test.ts --reporters=default --reporters=jest-junit",
1819
"test-demo": "NODE_OPTIONS=--experimental-vm-modules jest __tests__/demo/*.test.ts --reporters=default --reporters=jest-junit",
1920
"test-offline": "NODE_OPTIONS=--experimental-vm-modules jest __tests__/offline/*.test.ts --reporters=default --reporters=jest-junit",
20-
"all": "npm run build && npm run format && npm run lint && npm run package && npm run test-github"
21+
"all": "npm run build && npm run format && npm run lint && npm run package && npm run test-main"
2122
},
2223
"repository": {
2324
"type": "git",

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"noImplicitThis": true,
1111
"moduleResolution": "Node16",
1212
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
13+
"isolatedModules": true,
1314
"lib": [ "ESNext","ES2021.String", "dom"] /* Enable custom `ES2021.String` extension in typescript for `replaceAll` */
1415
},
1516
"exclude": ["node_modules", "__tests__/*.ts", "**/*.test.ts", "**/**/*.test.ts"],

0 commit comments

Comments
 (0)