Skip to content

Commit 9d1b8ff

Browse files
merceyzKent C. Dodds
andcommitted
fix: remove unnecessary packages (#52)
* fix: remove path-exists * fix: remove common-tags * fix: remove invariant * chore: update test wording * chore: fix eslint * Update index.js Co-authored-by: Kent C. Dodds <[email protected]>
1 parent 63d42c2 commit 9d1b8ff

File tree

4 files changed

+31
-43
lines changed

4 files changed

+31
-43
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
2727
"license": "MIT",
2828
"dependencies": {
29-
"common-tags": "^1.4.0",
30-
"invariant": "^2.2.2",
3129
"lodash.mergewith": "^4.6.0",
32-
"path-exists": "^4.0.0",
3330
"strip-indent": "^3.0.0"
3431
},
3532
"devDependencies": {

src/__tests__/__snapshots__/index.js.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`assert throws if code is unchanged + snapshot enabled 1`] = `"Code was unmodified but attempted to take a snapshot. If the code should not be modified, set \`snapshot: false\`"`;
4+
5+
exports[`assert throws if snapshot and output are both provided 1`] = `"\`output\` cannot be provided with \`snapshot: true\`"`;
6+
7+
exports[`assert throws if the plugin name is not inferable 1`] = `"The \`pluginName\` must be inferable or provided."`;
8+
9+
exports[`assert throws if there's no code 1`] = `"A string or object with a \`code\` or \`fixture\` property must be provided"`;
10+
311
exports[`can fail tests in fixtures at an absolute path 1`] = `"actual output does not match output.js"`;
412

513
exports[`default will throw if output changes 1`] = `"Expected output to not change, but it did"`;
@@ -22,18 +30,10 @@ exports[`tests cannot be both only-ed and skipped 1`] = `"Cannot enable both ski
2230

2331
exports[`throws an error if babelrc is true with no filename 1`] = `"babelrc set to true, but no filename specified in babelOptions"`;
2432

25-
exports[`throws an invariant if the plugin name is not inferable 1`] = `"The \`pluginName\` must be inferable or provided."`;
26-
2733
exports[`throws error if fixture provided and code changes 1`] = `"Expected output to not change, but it did"`;
2834

2935
exports[`throws error when error expected but no error thrown 1`] = `"Expected to throw error, but it did not."`;
3036

3137
exports[`throws error when function doesn't return true 1`] = `"[BABEL] unknown: test message (While processing: \\"base$0\\")"`;
3238

3339
exports[`throws if output is incorrect 1`] = `"Output is incorrect."`;
34-
35-
exports[`throws invariant if code is unchanged + snapshot enabled 1`] = `"Code was unmodified but attempted to take a snapshot. If the code should not be modified, set \`snapshot: false\`"`;
36-
37-
exports[`throws invariant if snapshot and output are both provided 1`] = `"\`output\` cannot be provided with \`snapshot: true\`"`;
38-
39-
exports[`throws invariant if there's no code 1`] = `"A string or object with a \`code\` or \`fixture\` property must be provided"`;

src/__tests__/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ test('logs when plugin name is not inferable and rethrows errors', async () => {
8484
)
8585
})
8686

87-
test('throws an invariant if the plugin name is not inferable', async () => {
87+
test('assert throws if the plugin name is not inferable', async () => {
8888
await expect(
8989
runPluginTester({
9090
plugin: () => ({}),
@@ -184,7 +184,7 @@ test('throws if output is incorrect', async () => {
184184
await snapshotOptionsError(getOptions({tests}))
185185
})
186186

187-
test(`throws invariant if there's no code`, async () => {
187+
test(`assert throws if there's no code`, async () => {
188188
const tests = [{}]
189189
await snapshotOptionsError(getOptions({tests}))
190190
})
@@ -447,7 +447,7 @@ test('can overwrite plugin options at test level', async () => {
447447
)
448448
})
449449

450-
test('throws invariant if snapshot and output are both provided', async () => {
450+
test('assert throws if snapshot and output are both provided', async () => {
451451
const tests = [{code: simpleTest, output: 'anything', snapshot: true}]
452452
await snapshotOptionsError(getOptions({tests}))
453453
})
@@ -457,7 +457,7 @@ test('snapshot option can be derived from the root config', async () => {
457457
await snapshotOptionsError(getOptions({snapshot: true, tests}))
458458
})
459459

460-
test('throws invariant if code is unchanged + snapshot enabled', async () => {
460+
test('assert throws if code is unchanged + snapshot enabled', async () => {
461461
const tests = [simpleTest]
462462
await snapshotOptionsError(getOptions({snapshot: true, tests}))
463463
})

src/index.js

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ import assert from 'assert'
22
import path from 'path'
33
import fs from 'fs'
44
import {EOL} from 'os'
5-
import pathExists from 'path-exists'
65
import mergeWith from 'lodash.mergewith'
7-
import invariant from 'invariant'
86
import stripIndent from 'strip-indent'
9-
import {oneLine} from 'common-tags'
107

118
const noop = () => {}
129

@@ -135,18 +132,15 @@ function pluginTester({
135132

136133
// eslint-disable-next-line complexity
137134
function tester() {
138-
invariant(
135+
assert(
139136
code,
140-
oneLine`
141-
A string or object with a \`code\` or
142-
\`fixture\` property must be provided
143-
`,
137+
'A string or object with a `code` or `fixture` property must be provided',
144138
)
145-
invariant(
139+
assert(
146140
!babelOptions.babelrc || babelOptions.filename,
147141
'babelrc set to true, but no filename specified in babelOptions',
148142
)
149-
invariant(
143+
assert(
150144
!snapshot || !output,
151145
'`output` cannot be provided with `snapshot: true`',
152146
)
@@ -178,12 +172,9 @@ function pluginTester({
178172
)
179173

180174
if (snapshot) {
181-
invariant(
175+
assert(
182176
result !== code,
183-
oneLine`
184-
Code was unmodified but attempted to take a snapshot.
185-
If the code should not be modified, set \`snapshot: false\`
186-
`,
177+
'Code was unmodified but attempted to take a snapshot. If the code should not be modified, set `snapshot: false`',
187178
)
188179
const separator = '\n\n ↓ ↓ ↓ ↓ ↓ ↓\n\n'
189180
const formattedOutput = [code, separator, result].join('')
@@ -264,7 +255,7 @@ const createFixtureTests = (fixturesDir, options) => {
264255

265256
const rootOptionsPath = path.join(fixturesDir, 'options.json')
266257
let rootFixtureOptions = {}
267-
if (pathExists.sync(rootOptionsPath)) {
258+
if (fs.existsSync(rootOptionsPath)) {
268259
rootFixtureOptions = require(rootOptionsPath)
269260
}
270261

@@ -277,12 +268,12 @@ const createFixtureTests = (fixturesDir, options) => {
277268
const tsxCodePath = path.join(fixtureDir, 'code.tsx')
278269
const blockTitle = caseName.split('-').join(' ')
279270
const codePath =
280-
(pathExists.sync(jsCodePath) && jsCodePath) ||
281-
(pathExists.sync(tsCodePath) && tsCodePath) ||
282-
(pathExists.sync(jsxCodePath) && jsxCodePath) ||
283-
(pathExists.sync(tsxCodePath) && tsxCodePath)
271+
(fs.existsSync(jsCodePath) && jsCodePath) ||
272+
(fs.existsSync(tsCodePath) && tsCodePath) ||
273+
(fs.existsSync(jsxCodePath) && jsxCodePath) ||
274+
(fs.existsSync(tsxCodePath) && tsxCodePath)
284275
let fixturePluginOptions = {}
285-
if (pathExists.sync(optionsPath)) {
276+
if (fs.existsSync(optionsPath)) {
286277
fixturePluginOptions = require(optionsPath)
287278
}
288279

@@ -331,7 +322,7 @@ const createFixtureTests = (fixturesDir, options) => {
331322
],
332323
// if they have a babelrc, then we'll let them use that
333324
// otherwise, we'll just use our simple config
334-
babelrc: pathExists.sync(babelRcPath),
325+
babelrc: fs.existsSync(babelRcPath),
335326
},
336327
},
337328
rest,
@@ -427,7 +418,7 @@ function assertError(result, error) {
427418
`Expected ${result.message} to match ${error}`,
428419
)
429420
} else {
430-
invariant(
421+
assert(
431422
typeof error === 'boolean',
432423
'The given `error` must be a function, string, boolean, or RegExp',
433424
)
@@ -445,17 +436,17 @@ function getPluginName(plugin, babel) {
445436
} catch (error) {
446437
// eslint-disable-next-line no-console
447438
console.error(
448-
oneLine`
449-
Attempting to infer the name of your plugin failed.
450-
Tried to invoke the plugin which threw the error.
451-
`,
439+
'Attempting to infer the name of your plugin failed. Tried to invoke the plugin which threw the error.',
452440
)
453441
throw error
454442
}
455-
invariant(name, 'The `pluginName` must be inferable or provided.')
443+
assert(name, 'The `pluginName` must be inferable or provided.')
456444
return name
457445
}
458446

447+
// unfortunately the ESLint plugin for Jest thinks this is a test file
448+
// a better solution might be to adjust the eslint config so it doesn't
449+
// but I don't have time to do that at the moment.
459450
/*
460451
eslint
461452
complexity: off,

0 commit comments

Comments
 (0)