diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69079f2..2d991b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 26dbbfc..23fc138 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -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') diff --git a/package.json b/package.json index f8994d0..709897b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tsconfig.json b/tsconfig.json index 10a7a05..a7c6063 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"],