|
| 1 | +name: Internal - Tests for test action |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +permissions: {} |
| 7 | + |
| 8 | +jobs: |
| 9 | + test-report: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: read |
| 13 | + strategy: |
| 14 | + fail-fast: false |
| 15 | + matrix: |
| 16 | + failure: [false, true] |
| 17 | + steps: |
| 18 | + - name: Arrange - Checkout |
| 19 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 20 | + with: |
| 21 | + persist-credentials: false |
| 22 | + - name: Arrange - Create a dependency-free native test project |
| 23 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 24 | + with: |
| 25 | + script: | |
| 26 | + const fs = require('node:fs'); |
| 27 | + await io.mkdirP('report-fixture'); |
| 28 | + await io.cp('.node-version', 'report-fixture/.node-version'); |
| 29 | + fs.writeFileSync('report-fixture/package.json', JSON.stringify({ |
| 30 | + name: 'report-fixture', version: '1.0.0', private: true, |
| 31 | + scripts: { |
| 32 | + 'pretest:ci': 'node -e "require(\'node:fs\').mkdirSync(\'.reports\', {recursive:true})"', |
| 33 | + 'test:ci': 'node --experimental-test-coverage --test --test-reporter=spec --test-reporter-destination=stdout --test-reporter=junit --test-reporter-destination=.reports/junit.xml --test-reporter=lcov --test-reporter-destination=.reports/lcov.info test.cjs', |
| 34 | + }, |
| 35 | + })); |
| 36 | + fs.writeFileSync('report-fixture/source.cjs', 'module.exports = value => value;\n'); |
| 37 | + fs.writeFileSync('report-fixture/test.cjs', "require('node:test').test('report fixture', () => require('node:assert/strict').equal(require('./source.cjs')(process.env.EXPECT_FAILURE), 'false'));\n"); |
| 38 | + await exec.exec('npm', ['install', '--package-lock-only', '--ignore-scripts', '--no-audit', '--no-fund'], { cwd: 'report-fixture' }); |
| 39 | + - name: Act - Run tests with comments disabled and no write token |
| 40 | + id: test |
| 41 | + continue-on-error: true |
| 42 | + uses: $/actions/test |
| 43 | + env: |
| 44 | + EXPECT_FAILURE: ${{ matrix.failure }} |
| 45 | + with: |
| 46 | + working-directory: report-fixture |
| 47 | + comment: "false" |
| 48 | + report-file: | |
| 49 | + .reports/junit.xml |
| 50 | + .reports/lcov.info |
| 51 | + - name: Assert - Retrieve reports even after a failed test |
| 52 | + if: steps.test.outputs.report-artifact-id != '' |
| 53 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 54 | + with: |
| 55 | + artifact-ids: ${{ steps.test.outputs.report-artifact-id }} |
| 56 | + path: downloaded-reports |
| 57 | + merge-multiple: true |
| 58 | + - name: Assert - Verify outcome and native report content |
| 59 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 60 | + env: |
| 61 | + ACTUAL: ${{ steps.test.outcome }} |
| 62 | + EXPECTED: ${{ matrix.failure && 'failure' || 'success' }} |
| 63 | + ARTIFACT_ID: ${{ steps.test.outputs.report-artifact-id }} |
| 64 | + with: |
| 65 | + script: | |
| 66 | + const assert = require('node:assert/strict'); |
| 67 | + const fs = require('node:fs'); |
| 68 | + assert.equal(process.env.ACTUAL, process.env.EXPECTED); |
| 69 | + assert.match(process.env.ARTIFACT_ID, /^\d+$/); |
| 70 | + const globber = await glob.create('downloaded-reports/**/*', { matchDirectories: false }); |
| 71 | + const files = await globber.glob(); |
| 72 | + assert.equal(files.length, 2); |
| 73 | + const junit = fs.readFileSync(files.find(file => file.endsWith('junit.xml')), 'utf8'); |
| 74 | + assert.equal(junit.includes('<failure'), process.env.EXPECTED === 'failure'); |
| 75 | + assert.match(fs.readFileSync(files.find(file => file.endsWith('lcov.info')), 'utf8'), /SF:/); |
0 commit comments