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 7, 2022
1 parent df6aeff commit 7bc88c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ 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
Expand All @@ -17,5 +17,5 @@ jobs:
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 @@ -39,15 +39,14 @@
"afinn-165": "^2.0.0"
},
"devDependencies": {
"@types/tape": "^4.0.0",
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"emoji-emotion": "^3.0.0",
"gemoji": "^7.0.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.52.0"
Expand Down
47 changes: 24 additions & 23 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import fs from 'node:fs'
import assert from 'node:assert/strict'
import fs from 'node:fs/promises'
import path from 'node:path'
import test from 'tape'
import test from 'node:test'
import {polarity, inject} from '../index.js'

test('polarity()', function (t) {
t.equal(typeof polarity, 'function', 'should be a `function`')
test('polarity()', function () {
assert.equal(typeof polarity, 'function', 'should be a `function`')

t.deepEqual(
assert.deepEqual(
polarity(['cool']),
{
polarity: 1,
Expand All @@ -18,7 +19,7 @@ test('polarity()', function (t) {
'should return a result object'
)

t.deepEqual(
assert.deepEqual(
// @ts-expect-error: missing.
polarity(),
{
Expand All @@ -31,7 +32,7 @@ test('polarity()', function (t) {
'should return a result object when no value is given'
)

t.deepEqual(
assert.deepEqual(
// @ts-expect-error: array-like
polarity({
length: 1,
Expand All @@ -47,7 +48,7 @@ test('polarity()', function (t) {
'should return a result object when an array-like value is given'
)

t.deepEqual(
assert.deepEqual(
// @ts-expect-error: invalid
polarity(Number.POSITIVE_INFINITY),
{
Expand All @@ -60,7 +61,7 @@ test('polarity()', function (t) {
'should return a result object when an invalid value is given'
)

t.deepEqual(
assert.deepEqual(
polarity(['hate', 'hate', 'cat', 'hate', 'hate'], {cat: 5}),
{
polarity: -7,
Expand All @@ -74,7 +75,7 @@ test('polarity()', function (t) {

inject({cat: 5})

t.deepEqual(
assert.deepEqual(
polarity(['hate', 'hate', 'cat', 'hate', 'hate']),
{
polarity: -7,
Expand All @@ -88,7 +89,7 @@ test('polarity()', function (t) {

inject({cat: 0})

t.deepEqual(
assert.deepEqual(
polarity(['toString', 'prototype', 'constructor']),
{
polarity: 0,
Expand All @@ -100,7 +101,7 @@ test('polarity()', function (t) {
'should not throw when reaching for prototypal functions on `polarities`'
)

t.deepEqual(
assert.deepEqual(
polarity(['he', 'made', 'me', ':smile:']),
{
polarity: 2,
Expand All @@ -112,7 +113,7 @@ test('polarity()', function (t) {
'should accept gemoji'
)

t.deepEqual(
assert.deepEqual(
polarity(['he', 'made', 'me', '\uD83D\uDE31']),
{
polarity: -3,
Expand All @@ -123,24 +124,25 @@ test('polarity()', function (t) {
},
'should accept emoji'
)

t.end()
})

test('algorithm', function (t) {
const root = path.join('test', 'fixtures')
const files = fs.readdirSync(root)
test('algorithm', async function () {
const rootUrl = new URL('fixtures/', import.meta.url)
const files = await fs.readdir(rootUrl)
let index = -1

/* eslint-disable no-await-in-loop */
while (++index < files.length) {
if (path.extname(files[index]) !== '.txt') {
continue
}

const doc = fs.readFileSync(path.join(root, files[index]), 'utf8').trim()
const type = path.basename(files[index], '.txt').split('-')[1]
const stem = path.basename(files[index], '.txt')
const fixtureUrl = new URL(files[index], rootUrl)
const doc = String(await fs.readFile(fixtureUrl)).trim()
const type = stem.split('-')[1]

t.doesNotThrow(function () {
assert.doesNotThrow(function () {
const result = polarity(tokenize(doc))
const positive = type === 'positive'

Expand All @@ -154,8 +156,7 @@ test('algorithm', function (t) {
}
}, type + ': `' + doc + '`')
}

t.end()
/* eslint-enable no-await-in-loop */
})

/**
Expand Down

0 comments on commit 7bc88c5

Please sign in to comment.