Skip to content

Commit

Permalink
test: add test github workflow (#14)
Browse files Browse the repository at this point in the history
add tests against multiple versions of antora, nodejs. Not yet working for asciidoctor 3.x
  • Loading branch information
lask79 authored Feb 19, 2025
1 parent 2237152 commit 60d2dbf
Show file tree
Hide file tree
Showing 18 changed files with 1,039 additions and 28 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/test-antora.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test against Antora Versions

on:
push:
branches: [ '**' ]
paths:
- 'lib/antora/**'
- 'test/**'
- 'package.json'
- '.github/workflows/test-antora.yml'
pull_request:
branches: [ '**' ]
paths:
- 'lib/antora/**'
- 'test/**'
- 'package.json'
- '.github/workflows/test-antora.yml'
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
antora-version: ['~3.1', '3.2.0-alpha.8']

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install

- name: Install specific Antora version
run: |
npm install --no-save @antora/cli@${{ matrix.antora-version }} @antora/site-generator@${{ matrix.antora-version }}
# Ensure Asciidoctor is at ~2.2 as required by Antora
npm install --no-save @asciidoctor/core@~2.2
- name: Run Antora tests
run: npx jest tests/antora
53 changes: 53 additions & 0 deletions .github/workflows/test-asciidoctor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Test against Asciidoctor Versions

on:
push:
branches: [ '**' ]
paths:
- 'lib/**'
- 'test/**'
- 'package.json'
- '.github/workflows/test-asciidoctor.yml'
pull_request:
branches: [ '**' ]
paths:
- 'lib/**'
- 'test/**'
- 'package.json'
- '.github/workflows/test-asciidoctor.yml'
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
include:
# Test with Asciidoctor 2.2
- asciidoctor-version: '~2.2'
package-name: '@asciidoctor/core'
node-version: '18.x'
- asciidoctor-version: '~2.2'
package-name: '@asciidoctor/core'
node-version: '20.x'
- asciidoctor-version: '~2.2'
package-name: '@asciidoctor/core'
node-version: '22.x'

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm install

- name: Install specific Asciidoctor version
run: npm install --no-save ${{ matrix.package-name }}@${{ matrix.asciidoctor-version }}

- name: Run Asciidoctor tests
run: npx jest tests/asciidoctor
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
},
"asciidoc.extensions.registerWorkspaceExtensions": true,
"asciidoc.preview.refreshInterval": 500,
"jestTestExplorer.pathToJest": "node_modules/.bin/jest",
}
6 changes: 6 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,12 @@ Then that line will be marked as a comment.

:!sectnums:

=== v1.0.1

* *Improvements*
** Fixed documentation about how to use the extension in antora
** Added github actions to validate against asciidoctor, antora and nodejs versions

=== v1.0.0

* *Improvements*
Expand Down
3 changes: 1 addition & 2 deletions lib/antora/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ const validateConfig = require('./utils/validate-config')

module.exports = function (context, { playbook, config }, iconRegistry, cssGenerator) {
const logger = context.getLogger(packageName)
logger.info('Start Antora extension')
const validatedConfig = validateConfig(config, packageName, logger)

logger.info('Registering asciidoctor-treeview with config')
logger.info('Start Antora extension')
logger.info(' > Register asciidoctor-treeview as asciidoc extension')
playbook.asciidoc.extensions.push('asciidoctor-treeview')

Expand Down
3 changes: 1 addition & 2 deletions lib/antora/utils/validate-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ function validateConfig (config, packageName, logger) {

const validatedConfig = { iconSource }

logger.info(`Registering ${packageName} with config`)
logger.info(` > Icon Path: ${validatedConfig.iconPath}`)
logger.info(` > Icon Source: ${validatedConfig.iconSource}`)

return validatedConfig
}
Expand Down
4 changes: 0 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'

const toProc = require('./util/to-proc')
const { readFileSync } = require('fs')

const calloutsSubs = require('./callouts/callouts-substitutor')

const { getInstance: getIconRegistry } = require('./icons/icon-registry')
Expand Down Expand Up @@ -38,8 +36,6 @@ function registerDocInfoProcessor (context) {
const self = this
self.atLocation('header')
self.process(function (doc) {
// const css = readFileSync(require.resolve('../data/css/treeview.css'), { encoding: 'utf8' })

const iconPath = doc.getAttribute('treeview-icon-source') || 'jsdelivr'

const newCSS = cssGenerator.generateCss(iconRegistry, iconPath)
Expand Down
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
],
"license": "MPL-2.0",
"devDependencies": {
"@antora/cli": "^3.1.10",
"@antora/site-generator": "^3.1.10",
"@asciidoctor/core": "~2.2",
"@jest/globals": "^29.7.0",
"cross-env": "^7.0.3",
"eslint": "~7.32",
Expand All @@ -52,10 +49,10 @@
"prettier-eslint": "~13.0",
"stylelint": "^14.12.1",
"stylelint-config-standard": "^28.0.0",
"vscode-icons-js": "^11.6.1"
"vscode-icons-js": "^11.6.1",
"@asciidoctor/core": "~2.2"
},
"dependencies": {
"@asciidoctor/core": "~2.2",
"handlebars": "^4.7.8",
"material-icon-theme": "^5.19.0"
},
Expand Down
19 changes: 12 additions & 7 deletions tests/antora/antora-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ describe('Antora Extension', () => {
test('should not show warnings about incorrect extension registration', () => {
let output;
try {
output = execSync(`npx antora --stacktrace ${playbookPath}`, {
// Use the shell script that we know works
output = execSync(`${__dirname}/run-antora.sh ${playbookPath}`, {
encoding: 'utf8',
stdio: 'pipe'
});
Expand All @@ -47,6 +48,9 @@ describe('Antora Extension', () => {
})
.filter(line => line !== null);

// Debug output
console.log('Raw output:\n', output);

// Check for warnings about incorrect extension registration
const warningLines = logLines.filter(line =>
line.level === 'warn' &&
Expand All @@ -59,9 +63,11 @@ describe('Antora Extension', () => {
});

test('should complete build without fatal errors', () => {

let output;
try {
output = execSync(`npx antora --stacktrace ${playbookPath}`, {
// Use the shell script that we know works
output = execSync(`${__dirname}/run-antora.sh ${playbookPath}`, {
encoding: 'utf8',
stdio: 'pipe'
});
Expand All @@ -87,20 +93,19 @@ describe('Antora Extension', () => {
`Found fatal errors in build output:\n${JSON.stringify(fatalLines, null, 2)}`
);



// Verify expected info messages
const expectedMessages = [
'Registering asciidoctor-treeview with config',
'Start Antora extension',
'Handle UICatalog files',
'Generating treeview.css',
'Copying css/treeview.css to _/css'
];

// Check for expected messages in the output
expectedMessages.forEach(msg => {
const found = logLines.some(line =>
line.level === 'info' && line.msg.includes(msg)
);
expect(found).toBe(true, `Expected to find info message: ${msg}`);
expect(output.toLowerCase()).toContain(msg.toLowerCase());
});
});

Expand Down
4 changes: 4 additions & 0 deletions tests/antora/run-antora.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# Run Antora with stacktrace for better error reporting
npx antora --stacktrace "$1" 2>&1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { describe, it, expect, beforeEach } = require('@jest/globals')
const matchers = require('jest-extended')
expect.extend(matchers)

const TreeLine = require('../../lib/parser/treeline')
const TreeLine = require('../../../lib/parser/treeline')

describe('TreeLineToHtmlConverter', () => {
it('throws error when empty string is passed', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const matchers = require('jest-extended')
expect.extend(matchers)

const asciidoctor = require('@asciidoctor/core')()
const asciidoctorTreeView = require('../lib/index.js')
const asciidoctorTreeView = require('../../lib/index.js')

const example3Result = 'README.adoc'

Expand Down
2 changes: 1 addition & 1 deletion tests/full.test.js → tests/asciidoctor/full.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expect.extend(matchers)
const path = require('path')

const asciidoctor = require('@asciidoctor/core')()
const asciidoctorTreeView = require('../lib/index.js')
const asciidoctorTreeView = require('../../lib/index.js')

describe('Full Test', () => {
it('should render full page', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { describe, it, expect } = require('@jest/globals')
const matchers = require('jest-extended')
expect.extend(matchers)

const { getIconForFile, getIconForFolder } = require('../../lib/icons/icon-finder')
const { getIconForFile, getIconForFolder } = require('../../../lib/icons/icon-finder')
describe('IconFinder', () => {
describe('getIconForFile', () => {
it('throws error when empty string is passed', () => {
Expand Down
File renamed without changes.
Loading

0 comments on commit 60d2dbf

Please sign in to comment.