Skip to content

Commit

Permalink
What if we just wrote our own test reporter tho
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Nov 27, 2024
1 parent 41c9725 commit 081260d
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 34 deletions.
41 changes: 7 additions & 34 deletions .github/workflows/test-ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -119,27 +104,15 @@ 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
run: |
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({
Expand Down
99 changes: 99 additions & 0 deletions ui/test-reporter.js
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions ui/testem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

'use strict';
const JsonReporter = require('./test-reporter');

const config = {
test_page: 'tests/index.html?hidepassed',
Expand All @@ -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: {
Expand Down

0 comments on commit 081260d

Please sign in to comment.