Skip to content

Commit

Permalink
make tests faster
Browse files Browse the repository at this point in the history
  • Loading branch information
lask79 committed Feb 19, 2025
1 parent 6f5362b commit 1b404e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 92 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/test-antora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,4 @@ jobs:
npm install --no-save @asciidoctor/core@~2.2
- name: Run Antora tests
env:
# Force CI mode and logging settings
CI: "true"
FORCE_COLOR: "1"
ANTORA_LOG_FORMAT: "json"
ANTORA_LOG_LEVEL: "all"
DEBUG: "antora:*"
run: |
# Make the test script executable
chmod +x tests/antora/run-antora.sh
# Run tests with CI-specific settings
npx jest tests/antora --verbose --no-colors
run: npx jest tests/antora
53 changes: 4 additions & 49 deletions tests/antora/antora-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,7 @@ describe('Antora Extension', () => {
});

test('should complete build without fatal errors', () => {
// Debug: Print current working directory and file existence
console.log('Current working directory:', process.cwd());
console.log('Playbook exists:', fs.existsSync(playbookPath));
console.log('Playbook absolute path:', path.resolve(playbookPath));

// Debug: Print environment variables
console.log('Environment variables:', {
ANTORA_LOG_LEVEL: process.env.ANTORA_LOG_LEVEL,
DEBUG: process.env.DEBUG
});

let output;
try {
// Use the shell script that we know works
Expand Down Expand Up @@ -102,9 +93,7 @@ describe('Antora Extension', () => {
`Found fatal errors in build output:\n${JSON.stringify(fatalLines, null, 2)}`
);

// Debug log output
console.log('Raw output:', output);
console.log('Parsed log lines:', JSON.stringify(logLines, null, 2));


// Verify expected info messages
const expectedMessages = [
Expand All @@ -114,43 +103,9 @@ describe('Antora Extension', () => {
'Copying css/treeview.css to _/css'
];

// First check if we have any info messages at all
const infoMessages = logLines.filter(line => line.level === 'info').map(line => line.msg);
console.log('Info messages found:', infoMessages);

// First check if Antora actually ran
expect(output).toContain('=== Running Antora ===');
expect(output).toContain('=== Antora Run Complete ===');

// Extract the Antora run output (between the markers)
const antoraOutput = output.split('=== Running Antora ===')[1]?.split('=== Antora Run Complete ===')[0] || '';
console.log('Antora specific output:', antoraOutput);

// Try to parse lines as JSON first
const jsonLines = antoraOutput.split('\n')
.map(line => {
try {
return JSON.parse(line.trim());
} catch (e) {
return null;
}
})
.filter(line => line !== null);

console.log('Parsed JSON lines:', jsonLines);

// Check for expected messages in both JSON and plain text
// Check for expected messages in the output
expectedMessages.forEach(msg => {
const foundInJson = jsonLines.some(line =>
line.msg && line.msg.toLowerCase().includes(msg.toLowerCase())
);
const foundInPlainText = antoraOutput.toLowerCase().includes(msg.toLowerCase());

expect(foundInJson || foundInPlainText).toBe(true,
`Expected to find message: ${msg}\n` +
`In Antora output:\n${antoraOutput}\n` +
`Parsed JSON lines:\n${JSON.stringify(jsonLines, null, 2)}\n` +
`Full output:\n${output}`);
expect(output.toLowerCase()).toContain(msg.toLowerCase());
});
});

Expand Down
32 changes: 2 additions & 30 deletions tests/antora/run-antora.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,4 @@
#!/bin/bash
set -x # Print commands as they are executed

# Print environment info
echo "=== Environment Info ==="
echo "PWD: $(pwd)"
echo "Node version: $(node --version)"
echo "NPM version: $(npm --version)"

echo "=== Antora Version ==="
npx antora --version

echo "=== Setting Environment Variables ==="
export ANTORA_LOG_LEVEL=info
export DEBUG=antora:*

echo "=== Checking Playbook ==="
echo "Playbook path: $1"
ls -l "$1"

echo "=== Running Antora ==="

# Ensure we capture all output
if [ "$CI" = "true" ]; then
# CI run with explicit logging
ANTORA_LOG_LEVEL=all ANTORA_LOG_FORMAT=json npx antora --stacktrace "$1" 2>&1
else
# Regular local run
ANTORA_LOG_LEVEL=info npx antora --stacktrace "$1" 2>&1
fi

echo "=== Antora Run Complete ==="
# Run Antora with stacktrace for better error reporting
npx antora --stacktrace "$1" 2>&1

0 comments on commit 1b404e3

Please sign in to comment.