Skip to content

Commit

Permalink
Use Node test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 20, 2022
1 parent 125b399 commit 0d8956f
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 113 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ jobs:
name: ${{matrix.node}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dcodeIO/setup-node-nvm@master
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{matrix.node}}
- run: npm install
- run: npm test
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v3
strategy:
matrix:
node:
- lts/erbium
- lts/hydrogen
- node
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@
},
"devDependencies": {
"@types/mdast": "^3.0.0",
"@types/node": "^18.0.0",
"@types/pluralize": "^0.0.29",
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"mdast-util-heading-range": "^3.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"retext": "^8.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unist-builder": "^3.0.0",
Expand Down
201 changes: 94 additions & 107 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,46 @@
import test from 'tape'
import assert from 'node:assert/strict'
import test from 'node:test'
import {retext} from 'retext'
import retextProfanitiesFrench from './fr.js'
import retextProfanities from './index.js'

test('profanities', (t) => {
t.plan(8)
test('profanities', async () => {
const file = await retext().use(retextProfanities).process('Shit!')

retext()
.use(retextProfanities)
.process('Shit!')
.then((file) => {
t.deepEqual(
JSON.parse(JSON.stringify(file.messages)),
[
{
name: '1:1-1:5',
message: 'Don’t use `Shit`, it’s profane',
reason: 'Don’t use `Shit`, it’s profane',
line: 1,
column: 1,
source: 'retext-profanities',
ruleId: 'shit',
position: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 5, offset: 4}
},
fatal: false,
profanitySeverity: 2,
actual: 'Shit',
expected: [],
url: 'https://github.com/retextjs/retext-profanities#readme'
}
],
'should warn'
)
}, t.ifErr)

retext()
.use(retextProfanitiesFrench)
.process('Merde!')
.then((file) => {
t.deepEqual(
file.messages.map(String),
['1:1-1:6: Don’t use `Merde`, it’s profane'],
'should support other languages'
)
}, t.ifErr)

retext()
assert.deepEqual(
JSON.parse(JSON.stringify(file.messages)),
[
{
name: '1:1-1:5',
message: 'Don’t use `Shit`, it’s profane',
reason: 'Don’t use `Shit`, it’s profane',
line: 1,
column: 1,
source: 'retext-profanities',
ruleId: 'shit',
position: {
start: {line: 1, column: 1, offset: 0},
end: {line: 1, column: 5, offset: 4}
},
fatal: false,
profanitySeverity: 2,
actual: 'Shit',
expected: [],
url: 'https://github.com/retextjs/retext-profanities#readme'
}
],
'should warn'
)

const fileFr = await retext().use(retextProfanitiesFrench).process('Merde!')

assert.deepEqual(
fileFr.messages.map(String),
['1:1-1:6: Don’t use `Merde`, it’s profane'],
'should support other languages'
)

const fileLonger = await retext()
.use(retextProfanities)
.process(
[
Expand All @@ -56,55 +49,51 @@ test('profanities', (t) => {
'The kidnapper was the mother, an addict.'
].join('\n')
)
.then((file) => {
t.deepEqual(
file.messages.map(String),
[
'1:33-1:37: Be careful with `butt`, it’s profane in some cases',
'2:9-2:15: Don’t use `asshat`, it’s profane',
'3:34-3:40: Reconsider using `addict`, it may be profane'
],
'should warn about profanities'
)
}, t.ifErr)

retext()

assert.deepEqual(
fileLonger.messages.map(String),
[
'1:33-1:37: Be careful with `butt`, it’s profane in some cases',
'2:9-2:15: Don’t use `asshat`, it’s profane',
'3:34-3:40: Reconsider using `addict`, it may be profane'
],
'should warn about profanities'
)

const ignore = await retext()
.use(retextProfanities, {ignore: ['butt']})
.process('He’s pretty set on beating your butt for sheriff.')
.then((file) => {
t.deepEqual(
file.messages.map(String),
[],
'should not warn for `ignore`d phrases'
)
}, t.ifErr)

retext()

assert.deepEqual(
ignore.messages.map(String),
[],
'should not warn for `ignore`d phrases'
)

const apostrophes = await retext()
.use(retextProfanities)
.process('When he’ll freeze over, hell freezes over.')
.then((file) => {
t.deepEqual(
file.messages.map(String),
['1:25-1:29: Be careful with `hell`, it’s profane in some cases'],
'should correctly depend on apostrophes'
)
}, t.ifErr)

retext()

await assert.deepEqual(
apostrophes.messages.map(String),
['1:25-1:29: Be careful with `hell`, it’s profane in some cases'],
'should correctly depend on apostrophes'
)

const pluralsAndSingulars = await retext()
.use(retextProfanities)
.process('slave slaves')
.then((file) => {
t.deepEqual(
file.messages.map(String),
[
'1:1-1:6: Don’t use `slave`, it’s profane',
'1:7-1:13: Don’t use `slaves`, it’s profane'
],
'should support plurals and singulars'
)
}, t.ifErr)

retext()

assert.deepEqual(
pluralsAndSingulars.messages.map(String),
[
'1:1-1:6: Don’t use `slave`, it’s profane',
'1:7-1:13: Don’t use `slaves`, it’s profane'
],
'should support plurals and singulars'
)

const sureness = await retext()
.use(retextProfanities, {sureness: 1})
.process(
[
Expand All @@ -113,25 +102,23 @@ test('profanities', (t) => {
'The kidnapper was the mother, an addict.'
].join('\n')
)
.then((file) => {
t.deepEqual(
file.messages.map(String),
[
'2:9-2:15: Don’t use `asshat`, it’s profane',
'3:34-3:40: Reconsider using `addict`, it may be profane'
],
'should warn about profanities'
)
}, t.ifErr)

retext()

assert.deepEqual(
sureness.messages.map(String),
[
'2:9-2:15: Don’t use `asshat`, it’s profane',
'3:34-3:40: Reconsider using `addict`, it may be profane'
],
'should warn about profanities'
)

const whoAre = await retext()
.use(retextProfanities)
.process(["who're", 'who’re', 'whore'].join('\n'))
.then((file) => {
t.deepEqual(
file.messages.map(String),
['3:1-3:6: Don’t use `whore`, it’s profane'],
'should not warn about `who are` contractions'
)
}, t.ifErr)

assert.deepEqual(
whoAre.messages.map(String),
['3:1-3:6: Don’t use `whore`, it’s profane'],
'should not warn about `who are` contractions'
)
})

0 comments on commit 0d8956f

Please sign in to comment.