Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move standard to node native test runner #1961

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
},
"scripts": {
"test": "npm run test-internal && npm run test-external",
"test-internal": "./bin/cmd.cjs --verbose && tape test/*.js",
"test-external": "tape test/external/*.js",
"test-internal": "./bin/cmd.cjs --verbose && node --test test/*.js",
"test-external": "node --test test/external/*.js",
"update-authors": "./tools/update-authors.sh && hallmark --fix AUTHORS.md"
},
"funding": [
Expand Down
16 changes: 8 additions & 8 deletions test/api.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import test from 'tape'
import assert from 'node:assert'
import test from 'node:test'
import standard from '../index.js'

test('api: lintFiles', async (t) => {
t.plan(2)
const [result] = await standard.lintFiles(['bin/cmd.cjs'])
t.equal(typeof result, 'object', 'result is an object')
t.equal(result.errorCount, 0)
// The node process calling this is at the root level
const [result] = await standard.lintFiles('./bin/cmd.cjs')
assert.equal(typeof result, 'object', 'result is an object')
assert.equal(result.errorCount, 0)
})

test('api: lintText', async (t) => {
t.plan(2)
const [result] = await standard.lintText('console.log("hi there")\n')
t.equal(typeof result, 'object', 'result is an object')
t.equal(result.errorCount, 1, 'should have used single quotes')
assert.equal(typeof result, 'object', 'result is an object')
assert.equal(result.errorCount, 1, 'should have used single quotes')
})
9 changes: 4 additions & 5 deletions test/cmd.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { fileURLToPath } from 'node:url'
import test from 'tape'
import assert from 'node:assert'
import test from 'node:test'
import crossSpawn from 'cross-spawn'

const CMD_PATH = fileURLToPath(new URL('../bin/cmd.cjs', import.meta.url))

test('command line usage: --help', t => {
t.plan(1)

const child = crossSpawn(CMD_PATH, ['--help'])
child.on('error', err => {
t.fail(err)
assert.fail(err)
})
child.on('close', code => {
t.equal(code, 0, 'zero exit code')
assert.equal(code, 0, 'zero exit code')
})
})
17 changes: 8 additions & 9 deletions test/external/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
* VERSION BUMP.)
*/

import assert from 'node:assert'
import { cpus } from 'node:os'
import { fileURLToPath } from 'node:url'
import test from 'node:test'
import { readFileSync, mkdirSync, access, R_OK, W_OK, writeFileSync } from 'node:fs'
import crossSpawn from 'cross-spawn'
import minimist from 'minimist'
import parallelLimit from 'run-parallel-limit'
import test from 'tape'

const testJsonPath = new URL('test.json', import.meta.url)
const json = readFileSync(testJsonPath, 'utf8')
Expand Down Expand Up @@ -56,13 +57,11 @@ if (!argv.disabled) {
disabledPkgs.forEach(pkg => {
console.log(`DISABLED: ${pkg.name}: ${pkg.disable} (${pkg.repo})`)
})
t.end()
t.skip()
})
}

test('test github repos that use `standard`', t => {
t.plan(pkgs.length)

mkdirSync(TMP, { recursive: true })

parallelLimit(pkgs.map(pkg => {
Expand All @@ -72,7 +71,7 @@ test('test github repos that use `standard`', t => {
return cb => {
access(folder, R_OK | W_OK, err => {
if (argv.offline && err) {
t.pass(`SKIPPING (offline): ${name} (${pkg.repo})`)
t.skip(`SKIPPING (offline): ${name} (${pkg.repo})`)
cb(null)
} else if (argv.offline) {
runStandard(cb)
Expand Down Expand Up @@ -121,15 +120,15 @@ test('test github repos that use `standard`', t => {
spawn('node', args, { cwd: folder }, err => {
const str = `${name} (${pkg.repo})`
if (err && argv.fix) {
t.comment(`Attempting --fix on ${str}`)
t.diagnostic(`Attempting --fix on ${str}`)
runStandardFix(cb)
} else if (err) {
markDisabled(name, true)
t.fail(str)
cb(null)
assert.fail(str)
} else {
markDisabled(name, false)
t.pass(str)
assert.ok(str)
cb(null)
}
})
Expand All @@ -140,7 +139,7 @@ test('test github repos that use `standard`', t => {
if (pkg.args) args.push(...pkg.args)
spawn('node', args, { cwd: folder }, err => {
const str = `${name} (${pkg.repo}) ** with --fix`
if (err) { t.fail(str) } else { t.pass(str) }
if (err) { assert.fail(str) } else { assert.ok(str) }
runGitReset(cb)
})
}
Expand Down
9 changes: 4 additions & 5 deletions test/validate-config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import test from 'tape'
import test from 'node:test'
import assert from 'node:assert'
import standard from '../index.js'

test('load config in eslint to validate all rule syntax is correct', async function (t) {
t.plan(1)
const code = 'const foo = 1\nconst bar = function () {}\nbar(foo)\n'
const [result] = await standard.lintText(code)
t.equal(result.errorCount, 0)
assert.equal(result.errorCount, 0)
})

test('ensure we allow top level await', async function (t) {
t.plan(1)
const code = 'const foo = await 1\nconst bar = function () {}\nawait bar(foo)\n'
const [result] = await standard.lintText(code)
t.equal(result.errorCount, 0)
assert.equal(result.errorCount, 0)
})