Skip to content

Commit

Permalink
fix: tap.includes -> tap.match
Browse files Browse the repository at this point in the history
Fixes Tap v15's deprecation notice
  • Loading branch information
hdoro committed Oct 11, 2021
1 parent 6440eed commit a9b58d7
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 82 deletions.
28 changes: 14 additions & 14 deletions test/build-npm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,87 +12,87 @@ tap.test('throws on missing package.json', options, async (t) => {
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'No package.json found')
t.match(stderr, 'No package.json found')
})

tap.test('throws on package.json being... not a file', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'folder-package-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'EISDIR')
t.match(stderr, 'EISDIR')
})

tap.test('throws on package.json being invalid JSON', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'invalid-package-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'Unexpected token')
t.match(stderr, 'Unexpected token')
})

tap.test('throws on package.json being invalid JSON (not an object)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'invalid-package-json-shape')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'Root must be an object')
t.match(stderr, 'Root must be an object')
})

tap.test('throws on package.json being invalid (non-string name)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'misnamed-package-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"name" must be a string')
t.match(stderr, '"name" must be a string')
})

tap.test('throws on package.json being invalid (not allowed npm name)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'disallowed-package-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'name can only contain URL-friendly characters')
t.match(stderr, 'name can only contain URL-friendly characters')
})

tap.test('throws on package.json being invalid (unscoped without plugin prefix)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'unprefixed-package-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'prefixed with "sanity-plugin-"')
t.match(stderr, 'prefixed with "sanity-plugin-"')
})

tap.test('throws on package.json being invalid (non-string "main")', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'nonstring-main-package-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"main" must be a string if defined')
t.match(stderr, '"main" must be a string if defined')
})

tap.test('throws on package.json being invalid (references source dir)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'sourced-package-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"main" points to file within source')
t.match(stderr, '"main" points to file within source')
})

tap.test('throws on package.json being invalid (references orphaned file)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'orphaned-package-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"main" points to file that will not exist after compiling')
t.match(stderr, '"main" points to file that will not exist after compiling')
})

tap.test('throws on package.json being invalid (references missing file)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'targetless-package-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(
t.match(
stderr,
'"main" points to file that does not exist, and no equivalent is found in source directory'
)
Expand All @@ -105,7 +105,7 @@ tap.test(
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(
t.match(
stderr,
'"main" points to file that does not exist, and "paths" is not configured to compile to this location'
)
Expand All @@ -117,13 +117,13 @@ tap.test('throws on package.json being invalid (references file without `paths`)
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"main" points to file that does not exist')
t.match(stderr, '"main" points to file that does not exist')
})

tap.test('throws on double lockfile', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'double-lockfile')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'contains both package-lock.json and yarn.lock')
t.match(stderr, 'contains both package-lock.json and yarn.lock')
})
34 changes: 17 additions & 17 deletions test/build-sanity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,119 +12,119 @@ tap.test('throws on missing sanity.json', options, async (t) => {
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'No sanity.json found')
t.match(stderr, 'No sanity.json found')
})

tap.test('throws on sanity.json being... not a file', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'folder-sanity-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'EISDIR')
t.match(stderr, 'EISDIR')
})

tap.test('throws on sanity.json being invalid JSON', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'invalid-sanity-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'Unexpected token')
t.match(stderr, 'Unexpected token')
})

tap.test('throws on sanity.json being invalid JSON (not an object)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'invalid-sanity-json-shape')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'Root must be an object')
t.match(stderr, 'Root must be an object')
})

tap.test('throws on sanity.json being invalid (non-boolean root)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'nonbool-sanity-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"root" property must be a boolean')
t.match(stderr, '"root" property must be a boolean')
})

tap.test('throws on sanity.json being invalid (contains project props)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'disallowed-sanity-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'Keys "api", "project" are not allowed')
t.match(stderr, 'Keys "api", "project" are not allowed')
})

tap.test('throws on sanity.json being invalid (truthy root)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'disallowed-root-sanity-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"root" cannot be truthy in a plugin manifest')
t.match(stderr, '"root" cannot be truthy in a plugin manifest')
})

tap.test('throws on sanity.json being invalid (non-object paths)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'nonobject-sanity-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"paths" must be an object if declared')
t.match(stderr, '"paths" must be an object if declared')
})

tap.test('throws on sanity.json being invalid (non-string compiled path)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'nonstring-compiled-sanity-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"paths" must have a (string) "compiled" property if declared')
t.match(stderr, '"paths" must have a (string) "compiled" property if declared')
})

tap.test('throws on sanity.json being invalid (non-string source path)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'nonstring-source-sanity-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"paths" must have a (string) "source" property if declared')
t.match(stderr, '"paths" must have a (string) "source" property if declared')
})

tap.test('throws on sanity.json being invalid (non-array parts)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'nonarray-parts-sanity-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"parts" must be an array if declared')
t.match(stderr, '"parts" must be an array if declared')
})

tap.test('throws on sanity.json being invalid (non-object part)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'nonobject-part-sanity-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"parts[0]" must be an object')
t.match(stderr, '"parts[0]" must be an object')
})

tap.test('throws on sanity.json being invalid (invalid part)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'invalid-part-sanity-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'Keys "name", "path" should be of type string (parts[0])')
t.match(stderr, 'Keys "name", "path" should be of type string (parts[0])')
})

tap.test('throws on sanity.json being invalid (invalid part keys)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'invalid-part-keys-sanity-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, 'Key "unknown" is not allowed in a part declaration (parts[1])')
t.match(stderr, 'Key "unknown" is not allowed in a part declaration (parts[1])')
})

tap.test('throws on sanity.json being invalid (unprefixed part)', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'unprefixed-part-sanity-json')
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(
t.match(
stderr,
'"name" must be prefixed with "part:unprefixed-part-sanity-json/" - got "some-part-name" (parts[0])'
)
Expand All @@ -135,12 +135,12 @@ tap.test('throws on sanity.json being invalid (unprefixed implementation)', opti
const {stdout, stderr, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(stdout, '', 'should have empty stdout')
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"implements" must be prefixed with "part:" - got "some-part-name" (parts[0])')
t.match(stderr, '"implements" must be prefixed with "part:" - got "some-part-name" (parts[0])')
})

tap.test('handles filenames with multiple dots', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'dotted-filename-part-sanity-json')
const {stdout, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(exitCode, 0, 'should have exit code 1')
t.includes(stdout, 'Successfully compiled 1 file with Babel')
t.match(stdout, 'Successfully compiled 1 file with Babel')
})
36 changes: 18 additions & 18 deletions test/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ tap.test('can build valid plugin (in cwd)', options, async (t) => {

const {stdout, stderr} = await execa(sanipack, ['build'], {cwd: fixtureDir})
t.equal(stderr, '', 'should have empty stderr')
t.includes(stdout, 'compiled 2 files')
t.match(stdout, 'compiled 2 files')
t.strictSame(await contents(outputDir), expectedFiles)
t.includes(await readFile(path.join(outputDir, 'one.js')), 'interopRequireDefault')
t.includes(await readFile(path.join(outputDir, 'styles', 'one.css')), 'bf1942')
t.match(await readFile(path.join(outputDir, 'one.js')), 'interopRequireDefault')
t.match(await readFile(path.join(outputDir, 'styles', 'one.css')), 'bf1942')

await rimraf(outputDir)
})
Expand All @@ -44,12 +44,12 @@ tap.test('can build valid plugin (specified path)', options, async (t) => {

const {stdout, stderr} = await execa(sanipack, ['build', fixtureDir])
t.equal(stderr, '', 'should have empty stderr')
t.includes(stdout, '/valid/src')
t.includes(stdout, '/valid/lib')
t.includes(stdout, 'compiled 2 files')
t.match(stdout, '/valid/src')
t.match(stdout, '/valid/lib')
t.match(stdout, 'compiled 2 files')
t.strictSame(await contents(outputDir), expectedFiles)
t.includes(await readFile(path.join(outputDir, 'one.js')), 'interopRequireDefault')
t.includes(await readFile(path.join(outputDir, 'styles', 'one.css')), 'bf1942')
t.match(await readFile(path.join(outputDir, 'one.js')), 'interopRequireDefault')
t.match(await readFile(path.join(outputDir, 'styles', 'one.css')), 'bf1942')

await rimraf(outputDir)
})
Expand All @@ -64,8 +64,8 @@ tap.test('can build valid plugin (silently)', options, async (t) => {
t.equal(stderr, '', 'should have empty stderr')
t.equal(stdout, '', 'should have empty stdout')
t.strictSame(await contents(outputDir), expectedFiles)
t.includes(await readFile(path.join(outputDir, 'one.js')), 'interopRequireDefault')
t.includes(await readFile(path.join(outputDir, 'styles', 'one.css')), 'bf1942')
t.match(await readFile(path.join(outputDir, 'one.js')), 'interopRequireDefault')
t.match(await readFile(path.join(outputDir, 'styles', 'one.css')), 'bf1942')

await rimraf(outputDir)
})
Expand All @@ -78,12 +78,12 @@ tap.test('can build typescript plugin', options, async (t) => {

const {stdout, stderr} = await execa(sanipack, ['build'], {cwd: fixtureDir})
t.equal(stderr, '', 'should have empty stderr')
t.includes(stdout, '/ts/src')
t.includes(stdout, '/ts/lib')
t.includes(stdout, 'compiled 2 files')
t.match(stdout, '/ts/src')
t.match(stdout, '/ts/lib')
t.match(stdout, 'compiled 2 files')
t.strictSame(await contents(outputDir), expectedFiles)
t.includes(await readFile(path.join(outputDir, 'one.js')), 'interopRequireDefault')
t.includes(await readFile(path.join(outputDir, 'styles', 'one.css')), 'bf1942')
t.match(await readFile(path.join(outputDir, 'one.js')), 'interopRequireDefault')
t.match(await readFile(path.join(outputDir, 'styles', 'one.css')), 'bf1942')

await rimraf(outputDir)
})
Expand All @@ -92,7 +92,7 @@ tap.test('can "build" (skip) plugin without compilation', options, async (t) =>
const fixtureDir = path.join(baseFixturesDir, 'plain')
const {stdout, stderr} = await execa(sanipack, ['build'], {cwd: fixtureDir})
const before = await contents(fixtureDir)
t.includes(stderr, 'will not compile')
t.match(stderr, 'will not compile')
t.equal(stdout, '', 'should have empty stdout')
t.strictSame(await contents(fixtureDir), before)
})
Expand All @@ -114,7 +114,7 @@ tap.test('throws on invalid source map flag', options, async (t) => {
})
const before = await contents(fixtureDir)
t.equal(exitCode, 2)
t.includes(stderr, 'Invalid --source-maps option: "foo"')
t.includes(stdout, '[true|false|inline|both]')
t.match(stderr, 'Invalid --source-maps option: "foo"')
t.match(stdout, '[true|false|inline|both]')
t.strictSame(await contents(fixtureDir), before)
})
Loading

0 comments on commit a9b58d7

Please sign in to comment.