diff --git a/.github/workflows/test-ui.yml b/.github/workflows/test-ui.yml index 9007ab81e5b..c76dbc4c1f0 100644 --- a/.github/workflows/test-ui.yml +++ b/.github/workflows/test-ui.yml @@ -61,33 +61,18 @@ jobs: jwtGithubAudience: ${{ vars.CI_VAULT_AUD }} secrets: |- kv/data/teams/nomad/ui PERCY_TOKEN ; - # - name: Create results directory - # run: mkdir -p ui/test-results - # - name: ember exam - # env: - # PERCY_TOKEN: ${{ env.PERCY_TOKEN || secrets.PERCY_TOKEN }} - # PERCY_PARALLEL_NONCE: ${{ needs.pre-test.outputs.nonce }} - # run: | - # yarn exam:parallel --split=${{ matrix.split }} --partition=${{ matrix.partition }} --json-report=test-results-${{ matrix.partition }}.json - - name: Create fake file - working-directory: ui + - name: ember exam + env: + PERCY_TOKEN: ${{ env.PERCY_TOKEN || secrets.PERCY_TOKEN }} + PERCY_PARALLEL_NONCE: ${{ needs.pre-test.outputs.nonce }} run: | - mkdir -p test-results - # touch test-results/faux-${{ matrix.partition }}.json - echo '{"testResults": [{"name": "Test '${{ matrix.partition }}'", "time": '${{ matrix.partition }}'00}]}' > test-results/faux-${{ matrix.partition }}.json - ls -la test-results/ # Debug: List directory contents - pwd # Debug: Show current directory - echo "File exists: $(test -f test-results/faux-${{ matrix.partition }}.json && echo "yes" || echo "no")" - - # run: | - # mkdir -p test-results - # touch test-results/faux-${{ matrix.partition }}.json + yarn exam:parallel --split=${{ matrix.split }} --partition=${{ matrix.partition }} --json-report=test-results/test-results-${{ matrix.partition }}.json - name: Upload partition test results # if: github.event_name == 'push' && github.ref == 'refs/heads/main' uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 with: name: test-results-${{ matrix.partition }} - path: ui/test-results/faux-${{ matrix.partition }}.json + path: ui/test-results/test-results-${{ matrix.partition }}.json retention-days: 90 finalize: needs: @@ -119,15 +104,6 @@ jobs: pattern: test-results-* path: test-results - - name: Debug directory structure - run: | - echo "Current directory:" - pwd - echo "Root directory contents:" - ls -la .. - echo "Test results directory contents:" - ls -la ../test-results || echo "test-results directory not found" - - name: Combine test results for comparison # if: github.event_name == 'push' && github.ref == 'refs/heads/main' # Note: iterator is hardcoded to 4 to match matrix partitions @@ -135,11 +111,8 @@ jobs: node -e " const fs = require('fs'); const results = []; - // Log where I am - console.log('Current directory:', process.cwd()); - for (let i = 1; i <= 4; i++) { - const data = JSON.parse(fs.readFileSync('../test-results/test-results-' + i + '/faux-' + i + '.json')); + const data = JSON.parse(fs.readFileSync('../test-results/test-results-' + i + '/test-results-' + i + '.json')); results.push(...data.testResults); } fs.writeFileSync('combined-test-results.json', JSON.stringify({ diff --git a/ui/test-reporter.js b/ui/test-reporter.js new file mode 100644 index 00000000000..cfc0b8e8ba7 --- /dev/null +++ b/ui/test-reporter.js @@ -0,0 +1,99 @@ +/* eslint-env node */ +/* eslint-disable no-console */ + +const fs = require('fs'); +const path = require('path'); + +class JsonReporter { + constructor(out, socket, config) { + // Prevent double initialization + if (JsonReporter.instance) { + return JsonReporter.instance; + } + JsonReporter.instance = this; + + this.out = out || process.stdout; + this.results = []; + + // Get output file from Testem config + this.outputFile = config.fileOptions.report_file || 'test-results.json'; + + console.log(`[Reporter] Initializing with output file: ${this.outputFile}`); + + try { + // Ensure output directory exists + fs.mkdirSync(path.dirname(this.outputFile), { recursive: true }); + + // Initialize the results file + fs.writeFileSync( + this.outputFile, + JSON.stringify( + { + summary: { total: 0, passed: 0, failed: 0 }, + timestamp: new Date().toISOString(), + tests: [], + }, + null, + 2 + ) + ); + console.log('[Reporter] Initialized results file'); + } catch (err) { + console.error('[Reporter] Error initializing results file:', err); + } + + process.on('SIGINT', () => { + console.log('[Reporter] Received SIGINT, finishing up...'); + this.finish(); + process.exit(0); + }); + } + + report(prefix, data) { + if (!data || !data.name) { + console.log(`[Reporter] Skipping invalid test result: ${data.name}`); + return; + } + + console.log(`[Reporter] Processing test: ${data.name}`); + + const result = { + name: data.name.trim(), + browser: prefix, + passed: !data.failed, + duration: data.runDuration, + error: data.failed ? data.error : null, + logs: (data.logs || []).filter((log) => log.type !== 'warn'), + }; + + this.results.push(result); + } + + writeCurrentResults() { + console.log('[Reporter] Writing current results...'); + try { + const output = { + summary: { + total: this.results.length, + passed: this.results.filter((r) => r.passed).length, + failed: this.results.filter((r) => !r.passed).length, + }, + timestamp: new Date().toISOString(), + tests: this.results, + }; + + fs.writeFileSync(this.outputFile, JSON.stringify(output, null, 2)); + console.log('[Reporter] Successfully wrote results'); + } catch (err) { + console.error('[Reporter] Error writing results:', err); + } + } + + finish() { + console.log('[Reporter] Finishing up...'); + this.writeCurrentResults(); + console.log('[Reporter] Done.'); + } +} + +module.exports = JsonReporter; diff --git a/ui/testem.js b/ui/testem.js index 7d1869af9ef..d973178bf02 100644 --- a/ui/testem.js +++ b/ui/testem.js @@ -4,6 +4,7 @@ */ 'use strict'; +const JsonReporter = require('./test-reporter'); const config = { test_page: 'tests/index.html?hidepassed', @@ -13,6 +14,8 @@ const config = { browser_start_timeout: 120, parallel: -1, framework: 'qunit', + reporter: JsonReporter, + report_file: 'test-results/test-results.json', browser_args: { // New format in testem/master, but not in a release yet // Chrome: {