Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v6.0.2
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
submodules: recursive
persist-credentials: false

- name: Initialize CodeQL
uses: github/codeql-action/init@v4.35.5
uses: github/codeql-action/init@9e0d7b8d25671d64c341c19c0152d693099fb5ba # v4.35.5
with:
languages: 'javascript'

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4.35.5
uses: github/codeql-action/analyze@9e0d7b8d25671d64c341c19c0152d693099fb5ba # v4.35.5
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v3.1.0
uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
- name: Enable auto-merge for Dependabot PRs
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/nodejs-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6.0.2
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
submodules: recursive
persist-credentials: false
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v6.4.0
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: lts/*
cache: npm
Expand All @@ -46,27 +47,31 @@ jobs:
- lts/*

steps:
- uses: actions/checkout@v6.0.2
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
submodules: recursive
persist-credentials: false
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v6.4.0
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm run build --if-present

- name: Run smoke tests
run: node scripts/smoke-test.js

- name: Run unit tests
run: npm run unit-tests
if: matrix.node != env.NODE_COV
if: matrix.node != env.NODE_COV && matrix.node != 18

- name: Run unit tests with coverage
run: npm run unit-tests-coverage
if: matrix.node == env.NODE_COV

- name: Run Coveralls
uses: coverallsapp/github-action@v2.3.7
uses: coverallsapp/github-action@5cbfd81b66ca5d10c19b062c04de0199c215fb6e # v2.3.7
if: matrix.node == env.NODE_COV
continue-on-error: true
with:
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ on:
branches:
- master

permissions: {}

jobs:
deploy:
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6.0.2
- uses: actions/setup-node@v6.4.0
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: lts/*
cache: npm
- run: npm ci
- name: Build docs
run: npm run build:docs
- name: Deploy
uses: peaceiris/actions-gh-pages@v4.1.0
uses: peaceiris/actions-gh-pages@84c30a85c19949d7eee79c4ff27748b70285e453 # v4.1.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/build
Expand Down
105 changes: 105 additions & 0 deletions scripts/smoke-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* eslint-disable no-console */
import assert from 'node:assert/strict';

const checks = [
{
name: 'parse5',
async run() {
const { parse, parseFragment, serialize, defaultTreeAdapter } = await import('parse5');
const doc = parse('<!DOCTYPE html><html><body><p>hi</p></body></html>');
assert.ok(doc, 'parse() returned a document');
const fragment = parseFragment('<div>x</div>');
assert.ok(fragment, 'parseFragment() returned a fragment');
assert.equal(typeof serialize(doc), 'string', 'serialize() returned a string');
assert.ok(defaultTreeAdapter, 'defaultTreeAdapter is exported');
},
},
{
name: 'parse5-htmlparser2-tree-adapter',
async run() {
const { parse } = await import('parse5');
const { adapter } = await import('parse5-htmlparser2-tree-adapter');
assert.ok(adapter, 'adapter is exported');
const doc = parse('<p>hi</p>', { treeAdapter: adapter });
assert.ok(doc, 'parse() with htmlparser2 adapter returned a document');
},
},
{
name: 'parse5-sax-parser',
async run() {
const { SAXParser } = await import('parse5-sax-parser');
const parser = new SAXParser();
const tags = [];
parser.on('startTag', (tag) => tags.push(tag.tagName));
await new Promise((resolve, reject) => {
parser.on('finish', resolve);
parser.on('error', reject);
parser.end('<p>hello</p>');
});
assert.deepEqual(tags, ['p'], 'SAXParser emitted expected startTag');
},
},
{
name: 'parse5-parser-stream',
async run() {
const { ParserStream } = await import('parse5-parser-stream');
const stream = new ParserStream();
await new Promise((resolve, reject) => {
stream.on('finish', resolve);
stream.on('error', reject);
stream.end('<p>hello</p>');
});
assert.ok(stream.document, 'ParserStream produced a document');
},
},
{
name: 'parse5-plain-text-conversion-stream',
async run() {
const { PlainTextConversionStream } = await import('parse5-plain-text-conversion-stream');
const stream = new PlainTextConversionStream();
await new Promise((resolve, reject) => {
stream.on('finish', resolve);
stream.on('error', reject);
stream.end('hello world');
});
assert.ok(stream.document, 'PlainTextConversionStream produced a document');
},
},
{
name: 'parse5-html-rewriting-stream',
async run() {
const { RewritingStream } = await import('parse5-html-rewriting-stream');
const stream = new RewritingStream();
let output = '';
stream.on('data', (chunk) => {
output += chunk;
});
await new Promise((resolve, reject) => {
stream.on('finish', resolve);
stream.on('error', reject);
stream.end('<p>hello</p>');
});
assert.equal(output, '<p>hello</p>', 'RewritingStream passed content through');
},
},
];

let failures = 0;
for (const { name, run } of checks) {
try {
await run();
console.log(`ok - ${name}`);
} catch (error) {
failures++;
console.error(`not ok - ${name}`);
console.error(error);
}
}

if (failures > 0) {
console.error(`\n${failures} smoke test(s) failed`);
// eslint-disable-next-line unicorn-x/no-process-exit
process.exit(1);
}

console.log(`\nAll ${checks.length} smoke tests passed`);