Skip to content

Commit

Permalink
Merge pull request #36 from x-govuk/node-test
Browse files Browse the repository at this point in the history
Use Node test runner
  • Loading branch information
paulrobertlloyd authored Dec 10, 2023
2 parents fbdd3e0 + a92aeb9 commit 56ca1bc
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 1,155 deletions.
1,114 changes: 4 additions & 1,110 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 2 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
},
"scripts": {
"lint": "standard && stylelint 'x-govuk/**/*.scss'",
"test": "mocha",
"test:watch": "mocha --watch",
"coverage": "c8 mocha"
"test": "node --test",
"coverage": "node --test --experimental-test-coverage"
},
"publishConfig": {
"access": "public"
Expand All @@ -36,10 +35,8 @@
"highlight.js": "^11.5.0"
},
"devDependencies": {
"c8": "^7.11.0",
"markdown-it": "^13.0.1",
"markdown-it-testgen": "^0.1.6",
"mocha": "^10.0.0",
"standard": "^17.0.0",
"stylelint": "^14.6.1",
"stylelint-config-gds": "^0.2.0"
Expand All @@ -57,12 +54,6 @@
"require": "./lib/highlight.js"
}
},
"c8": {
"reporter": [
"text",
"lcovonly"
]
},
"stylelint": {
"extends": "stylelint-config-gds/scss"
}
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/govuk.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
desc: Converts Markdown into GOV.UK Frontend-compliant HTML
---

.
# Heading 1
.
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/option-calvert-fractions.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
desc: Improves typography (fractions only)
---

.
1/2 2/3
.
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/option-calvert-guillemets.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
desc: Improves typography (guillemets only)
---

.
1/2 2/3
.
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/option-calvert-mathematical.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
desc: Improves typography (mathematical symbols only)
---

.
1/2 2/3
.
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/option-calvert.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
desc: Improves all typography
---

.
1/2 2/3
.
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/option-heading-starts-with.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
desc: Starts headings with xl size
---

.
# Heading 1
.
Expand Down
56 changes: 22 additions & 34 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
const { describe } = require('mocha')
const assert = require('node:assert')
const { it, describe } = require('node:test')
const testGenerator = require('markdown-it-testgen')
const markdownIt = require('markdown-it')

describe('Converts Markdown into GOV.UK Frontend-compliant HTML', () => {
const md = require('markdown-it')().use(require('../index.js'))
// `testGenerator` uses Mocha internally, but we’re using node:test
global.describe = describe
global.it = it

testGenerator('./test/fixtures/govuk.txt', md)
})

describe('Starts headings with xl size', () => {
const md = require('markdown-it')().use(require('../index.js'), {
headingsStartWith: 'xl'
})
const testMarkdown = (path, options = {}) => {
const md = markdownIt().use(require('../index.js'), options)

testGenerator('./test/fixtures/option-heading-starts-with.txt', md)
})
testGenerator(path, { assert }, md)
}

describe('Improves all typography', () => {
const md = require('markdown-it')().use(require('../index.js'), {
calvert: true
})
testMarkdown('./test/fixtures/govuk.txt')

testGenerator('./test/fixtures/option-calvert.txt', md)
testMarkdown('./test/fixtures/option-heading-starts-with.txt', {
headingsStartWith: 'xl'
})

describe('Improves typography (fractions only)', () => {
const md = require('markdown-it')().use(require('../index.js'), {
calvert: ['fractions']
})

testGenerator('./test/fixtures/option-calvert-fractions.txt', md)
testMarkdown('./test/fixtures/option-calvert.txt', {
calvert: true
})

describe('Improves typography (guillemets only)', () => {
const md = require('markdown-it')().use(require('../index.js'), {
calvert: ['guillemets']
})

testGenerator('./test/fixtures/option-calvert-guillemets.txt', md)
testMarkdown('./test/fixtures/option-calvert-fractions.txt', {
calvert: ['fractions']
})

describe('Improves typography (mathematical symbols only)', () => {
const md = require('markdown-it')().use(require('../index.js'), {
calvert: ['mathematical']
})
testMarkdown('./test/fixtures/option-calvert-guillemets.txt', {
calvert: ['guillemets']
})

testGenerator('./test/fixtures/option-calvert-mathematical.txt', md)
testMarkdown('./test/fixtures/option-calvert-mathematical.txt', {
calvert: ['mathematical']
})

0 comments on commit 56ca1bc

Please sign in to comment.