Skip to content

Commit

Permalink
prettier formatting, throw away throwaway scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Oct 10, 2023
1 parent 72018e9 commit f9470d5
Show file tree
Hide file tree
Showing 91 changed files with 602 additions and 444 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
/src/*/example
/.github
/src/*/dist
/src/*/.tshy
/src/test/test-built
/src/*/docs
/src/*/tap-snapshots
/tap-snapshots
/src/*/test/**/fixture
Expand Down
2 changes: 1 addition & 1 deletion src/after-each/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bring it back.

```ts
import t from 'tap'
t.afterEach((t) => {
t.afterEach(t => {
// this will run after each child test, all of their child
// tests, and so on
// the parameter is the child test that just ended.
Expand Down
10 changes: 5 additions & 5 deletions src/asserts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ to specify the formatting style, diff context lines, and so on.

It can contain the following fields:

* `sort` - boolean, sort items alphabetically by key.
* `bufferChunkSize` - number of bytes to show on each line when
- `sort` - boolean, sort items alphabetically by key.
- `bufferChunkSize` - number of bytes to show on each line when
printing buffers, default `32`
* `includeEnumerable` - boolean, include any and all enumerable
- `includeEnumerable` - boolean, include any and all enumerable
properties, including those inherited on the prototype chain.
By default, only `own` properties are shown.
* `includeGetters` - boolean, include getter properties.
* `diffContext` - how many lines of context to print around
- `includeGetters` - boolean, include getter properties.
- `diffContext` - how many lines of context to print around
changes in diffs, default `10`. Note that the test reporter
might use more or less than this value when displaying pretty
colored diffs.
Expand Down
6 changes: 0 additions & 6 deletions src/asserts/s.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion src/before-each/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bring it back.

```ts
import t from 'tap'
t.beforeEach((t) => {
t.beforeEach(t => {
// this will run before each child test, all of their child
// tests, and so on
// the parameter is the child test that is about to start.
Expand Down
2 changes: 1 addition & 1 deletion src/before/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ t.test('first test', t => {
console.error('before in first test')
})
console.error('in first test')
t.test('child test', (t) => {
t.test('child test', t => {
console.error('child of first test')
t.end()
})
Expand Down
6 changes: 5 additions & 1 deletion src/clock/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ t.equal(t.pluginLoaded(plugin), false, 'not loaded by default')
//@ts-expect-error
t.equal(t.clock, undefined)
t.match(withClock.clock, Clock, 't.clock is a Clock')
t.equal(withClock.clock, withClock.clock, 'getter returns same object each time')
t.equal(
withClock.clock,
withClock.clock,
'getter returns same object each time'
)
2 changes: 1 addition & 1 deletion src/core/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ export class Base<
this.parser.on('line', l => this.#online(l))
this.parser.once('bailout', reason => this.onbail(reason))
this.parser.on('complete', result => this.oncomplete(result))
this.parser.on('result', (res) => this.#onParserResult(res))
this.parser.on('result', res => this.#onParserResult(res))
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/core/src/main-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { argv, proc } from './proc.js'
*/
export const mainScript = (def: string = 'TAP') => {
//@ts-ignore
if (typeof repl !== 'undefined' || proc._forceRepl || '_eval' in proc) {
if (
typeof repl !== 'undefined' ||
proc._forceRepl ||
'_eval' in proc
) {
return def
}
return argv[1] || def
Expand Down
3 changes: 2 additions & 1 deletion src/core/src/message-from-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const messageFromError = (er: unknown): string => {
const { name, message, stack, error, code } = er
if (error && typeof error == 'string') return error
const nc = name && typeof name === 'string' ? `${name}: ` : ''
const ncCode = nc && typeof code === 'string' ? `${name} [${code}]: `: ''
const ncCode =
nc && typeof code === 'string' ? `${name} [${code}]: ` : ''
if (message && typeof message === 'string') return message
if (typeof stack === 'string' && stack.trim()) {
const lines = stack.trim().split('\n')
Expand Down
3 changes: 2 additions & 1 deletion src/core/src/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ export class Spawn extends Base<SpawnEvents> {
!code &&
!signal
) {
this.options.skip = this.results.plan.skipReason || 'no tests found'
this.options.skip =
this.results.plan.skipReason || 'no tests found'
}

if (code || signal) {
Expand Down
46 changes: 27 additions & 19 deletions src/core/test/extra-from-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,19 @@ t.test('find a useful call site', t => {
er = e
}
const ex = extraFromError(er)
t.match(ex, {
at: {
constructor: CallSiteLike,
fileName: 'test/extra-from-error.ts',
lineNumber: Number,
columnNumber: Number,
t.match(
ex,
{
at: {
constructor: CallSiteLike,
fileName: 'test/extra-from-error.ts',
lineNumber: Number,
columnNumber: Number,
},
stack: String,
},
stack: String,
}, 'found a useful callsite below the top site')
'found a useful callsite below the top site'
)

const notUseful = Object.assign(new Error('no good'), {
stack: `RangeError: no good
Expand All @@ -142,17 +146,21 @@ t.test('find a useful call site', t => {
`,
})
const nex = extraFromError(notUseful)
t.matchStrict(nex, {
at: {
constructor: CallSiteLike,
lineNumber: null,
columnNumber: null,
fileName: null,
typeName: 'Some',
methodName: 'method (<anonymous>)',
functionName: 'Some.method (<anonymous>)',
t.matchStrict(
nex,
{
at: {
constructor: CallSiteLike,
lineNumber: null,
columnNumber: null,
fileName: null,
typeName: 'Some',
methodName: 'method (<anonymous>)',
functionName: 'Some.method (<anonymous>)',
},
stack: String,
},
stack: String,
}, 'did not find a useful site, use the top site')
'did not find a useful site, use the top site'
)
t.end()
})
4 changes: 2 additions & 2 deletions src/core/test/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ t.test('fallbacks', async t => {
value: undefined,
configurable: true,
})
const { proc, argv, cwd, env } = await t.mockImport(
const { proc, argv, cwd, env } = (await t.mockImport(
'../dist/esm/proc.js'
) as typeof import('../dist/esm/proc.js')
)) as typeof import('../dist/esm/proc.js')
Object.defineProperty(globalThis, 'process', {
value: process_,
configurable: true,
Expand Down
1 change: 0 additions & 1 deletion src/core/test/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const classes = [
['mjs', SpawnMJS, TestBaseMJS],
] as const


t.plan(2)
for (const [dialect, Spawn, TestBase] of classes) {
t.test(dialect, t => {
Expand Down
10 changes: 8 additions & 2 deletions src/core/test/tap-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ t.cleanSnapshot = s =>
/(typename|methodname|functionname|toplevel): [^\n]+\n/gi,
''
)
.replace(/test[\\\/]tap-file.ts:\d+:\d+/g, 'test/tap-file.ts:##:##')
.replace(
/test[\\\/]tap-file.ts:\d+:\d+/g,
'test/tap-file.ts:##:##'
)

t.test('replay a tap file', t => {
const content = `TAP version 14
Expand Down Expand Up @@ -91,6 +94,9 @@ t.test('name is not .. path', t => {
const rel = resolve('x.tap')
const abs = resolve('/absolute/path.tap')
t.equal(TapFile.getName(undefined, rel, process.cwd()), 'x')
t.equal(TapFile.getName(undefined, abs, process.cwd()), '/absolute/path')
t.equal(
TapFile.getName(undefined, abs, process.cwd()),
'/absolute/path'
)
t.end()
})
2 changes: 1 addition & 1 deletion src/core/test/tap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const main = () => {
child.stdout.on('data', c => out.push(c))
child.stderr.on('data', c => err.push(c))
let outEnded = false
child.stdout.on('end', () => outEnded = true)
child.stdout.on('end', () => (outEnded = true))
const res = await new Promise<Result>(res => {
child.on('close', (code, signal) => {
t.equal(outEnded, true, 'output ended')
Expand Down
56 changes: 31 additions & 25 deletions src/core/test/throw-to-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ not ok 2 - unhandled error
)
})

t.test('emit TAP failure and close out plan, with message', async t => {
const tb = new Base({ name: 'thrower' })
tb.parser.write('ok 1 - this is fine\n')
throwToParser(tb.parser, {
message: 'thrown to parser',
expect: true,
actual: false,
})
t.equal(
await tb.concat(),
`ok 1 - this is fine
t.test(
'emit TAP failure and close out plan, with message',
async t => {
const tb = new Base({ name: 'thrower' })
tb.parser.write('ok 1 - this is fine\n')
throwToParser(tb.parser, {
message: 'thrown to parser',
expect: true,
actual: false,
})
t.equal(
await tb.concat(),
`ok 1 - this is fine
not ok 2 - thrown to parser
---
expect: true
Expand All @@ -46,8 +48,9 @@ not ok 2 - thrown to parser
1..2
`
)
})
)
}
)

t.test('emit TAP failure, have plan already', async t => {
const tb = new Base({ name: 'thrower' })
Expand All @@ -72,20 +75,23 @@ not ok 2 - unhandled error
)
})

t.test('emit TAP failure, have plan already, with message', async t => {
const tb = new Base({ name: 'thrower' })
tb.parser.write('TAP version 14\n1..3\n')
tb.parser.write('ok 1 - this is fine\n')
throwToParser(tb.parser, {
message: 'hoopie doopie',
})
t.equal(
await tb.concat(),
`TAP version 14
t.test(
'emit TAP failure, have plan already, with message',
async t => {
const tb = new Base({ name: 'thrower' })
tb.parser.write('TAP version 14\n1..3\n')
tb.parser.write('ok 1 - this is fine\n')
throwToParser(tb.parser, {
message: 'hoopie doopie',
})
t.equal(
await tb.concat(),
`TAP version 14
1..3
ok 1 - this is fine
not ok 2 - hoopie doopie
# test count(2) != plan(3)
`
)
})
)
}
)
4 changes: 2 additions & 2 deletions src/create-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const plugin: TapPlugin<HelloSayer> = (t: TestBase) => {
return {
hello: (who: string = 'world') => {
console.error(`${t.name} says "Hello, ${who}!"`)
}
},
}
}
```
Expand Down Expand Up @@ -170,7 +170,7 @@ export class BreakProcess {
}

breakProcess() {
// if we already broke it,
// if we already broke it, nothing to do
if (this.#restore) return
const originalProcess = process
global.process = { not: 'the actual process object' }
Expand Down
11 changes: 7 additions & 4 deletions src/create-plugin/templates/src/hooks.mts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
// See the node docs for more information, or the @tapjs/dummy-plugin
// for an example.

import {GlobalPreloadHook, LoadHook, ResolveHook} from "module";
import { GlobalPreloadHook, LoadHook, ResolveHook } from 'module'

export const globalPreload:GlobalPreloadHook = ({ port }) => {
export const globalPreload: GlobalPreloadHook = ({ port }) => {
// this is a message port for communication between main and loader threads
port
return ''
Expand All @@ -19,8 +19,11 @@ export const globalPreload:GlobalPreloadHook = ({ port }) => {
export const load: LoadHook = async (url, context, nextLoad) =>
nextLoad(url, context)

export const resolve: ResolveHook = async (url, context, nextResolve) =>
nextResolve(url, context)
export const resolve: ResolveHook = async (
url,
context,
nextResolve
) => nextResolve(url, context)

// arguments are whatever data is passed in via Module.register() in import.mts
export const initialize = async () => {}
6 changes: 3 additions & 3 deletions src/create-plugin/templates/src/import.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// import Module from 'node:module'
// import { Serializable } from 'node:worker_threads'
//
//
// const { register } = Module as {
// register?: (
// url: string | URL,
Expand All @@ -13,7 +13,7 @@
// }
// ) => void
// }
//
//
// register?.(new URL('./loader.js', import.meta.url))
//
// Or:
Expand All @@ -35,7 +35,7 @@
import { register } from 'node:module'

// This is the main thread, do whatever setup needs to be done here.
// This triggers a call to initialize() to be run in the laoder thread,
// This triggers a call to initialize() to be run in the loader thread,
// which is defined in ./hooks.mts
//@ts-ignore
register(String(new URL('./loader.mjs', import.meta.url)), {
Expand Down
Loading

0 comments on commit f9470d5

Please sign in to comment.