Skip to content

Commit

Permalink
fix: expect-mocha-snapshot compatibility (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
dword-design authored Apr 26, 2021
1 parent b871682 commit e989d26
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@dword-design/functions": "^3.0.0",
"depcheck-package-name": "^1.0.1",
"execa": "^5.0.0",
"expect-mocha-snapshot": "dword-design/expect-mocha-snapshot#fork",
"fs-extra": "^9.1.0",
"jest-image-matcher": "^1.3.0",
"mocha": "^8.3.0",
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export const configureToMatchImageSnapshot = common => (
'Did you forget to pass `this` into expect().toMatchImageSnapshot(this)?'
)
}
if (!context.snapshotState) {
context.snapshotState = new jestSnapshot.SnapshotState(undefined, {
if (!context.imageSnapshotState) {
context.imageSnapshotState = new jestSnapshot.SnapshotState(undefined, {
updateSnapshot: process.env.SNAPSHOT_UPDATE ? 'all' : 'new',
})
}

const matcher = jestToMatchImageSnapshot.bind({
currentTestName: makeTestTitle(context.test),
snapshotState: context.snapshotState,
snapshotState: context.imageSnapshotState,
testPath: context.test.file,
})

Expand Down
34 changes: 34 additions & 0 deletions src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,40 @@ export default {
)
await execa.command('mocha --timeout 5000 index.spec.js')
}),
'expect-mocha-snapshot': () =>
withLocalTmpDir(async () => {
await outputFile(
'index.spec.js',
endent`
const sharp = require('${packageName`sharp`}')
const expect = require('expect')
const { toMatchImageSnapshot: self } = require('../src')
const toMatchSnapshot = require('${packageName`expect-mocha-snapshot`}')
expect.extend({ toMatchImageSnapshot: self })
expect.extend({ toMatchSnapshot })
it('image snapshot', async function () {
const img = await sharp({
create: {
background: { b: 0, g: 255, r: 0 },
channels: 3,
height: 48,
width: 48,
},
})
.png()
.toBuffer()
expect(img).toMatchImageSnapshot(this)
})
it('text snapshot', function () {
expect('foo').toMatchSnapshot(this)
})
`
)
await execa.command('mocha --timeout 5000 index.spec.js')
}),
'multiple snapshots per test': () =>
withLocalTmpDir(async () => {
await outputFile(
Expand Down
27 changes: 10 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1050,12 +1050,12 @@
"@babel/plugin-proposal-pipeline-operator" "^7.5.0"
"@babel/preset-env" "^7.6.3"
"@dword-design/functions" "^3.0.0"
"@vue/babel-preset-jsx" "github:dword-design/jsx#fork-babel-preset-jsx"
"@vue/babel-preset-jsx" dword-design/jsx#fork-babel-preset-jsx
babel-plugin-add-module-exports "^1.0.2"
babel-plugin-macros "^3.0.1"
babel-plugin-module-resolver "^4.0.0"
babel-plugin-transform-imports "^2.0.0"
babel-plugin-wildcard "github:dword-design/babel-plugin-wildcard#fork"
babel-plugin-wildcard dword-design/babel-plugin-wildcard#fork
depcheck-package-name "^1.0.0"
find-up "^5.0.0"
param-case "^3.0.3"
Expand Down Expand Up @@ -1097,7 +1097,7 @@
commitizen "^4.0.3"
constant-case "^3.0.3"
cz-conventional-changelog "^3.1.0"
depcheck "github:dword-design/depcheck#fork"
depcheck dword-design/depcheck#fork
depcheck-detector-execa "^1.2.1"
depcheck-detector-package-name "^1.0.0"
depcheck-package-name "^1.0.0"
Expand All @@ -1106,7 +1106,7 @@
execa "^5.0.0"
expect "^26.0.0"
expect-mocha-image-snapshot "^1.0.0"
expect-mocha-snapshot "github:dword-design/expect-mocha-snapshot#fork"
expect-mocha-snapshot dword-design/expect-mocha-snapshot#fork
find-up "^5.0.0"
fs-extra "^9.0.0"
get-projectz-readme-section-regex "^2.0.0"
Expand Down Expand Up @@ -1188,7 +1188,7 @@
integrity sha512-4Y0huP2ALcXgW3hPVujTVouX3piN9/yHr82FE2NvbqONwcMhjkucvA4xUMKXfn/+Yx3QG4y9VtSNPdTutu0ohQ==
dependencies:
delay "^5.0.0"
endent "github:dword-design/endent#fork"
endent dword-design/endent#fork
lodash "^4.17.15"
tinycolor2 "^1.4.1"

Expand Down Expand Up @@ -1730,9 +1730,8 @@
lodash.kebabcase "^4.1.1"
svg-tags "^1.0.0"

"@vue/babel-preset-jsx@github:dword-design/jsx#fork-babel-preset-jsx":
"@vue/babel-preset-jsx@dword-design/jsx#fork-babel-preset-jsx":
version "1.1.2"
uid a73cb9961541a60a66b1b99a69a32e00bc66d336
resolved "https://codeload.github.com/dword-design/jsx/tar.gz/a73cb9961541a60a66b1b99a69a32e00bc66d336"
dependencies:
"@vue/babel-helper-vue-jsx-merge-props" "^1.0.0"
Expand All @@ -1751,7 +1750,6 @@

"@vue/babel-sugar-inject-h@dword-design/jsx#fork-babel-sugar-inject-h":
version "1.1.2"
uid cc36a2200c059120f37944615fb2ec0e22f8f3cc
resolved "https://codeload.github.com/dword-design/jsx/tar.gz/cc36a2200c059120f37944615fb2ec0e22f8f3cc"
dependencies:
"@babel/plugin-syntax-jsx" "^7.2.0"
Expand Down Expand Up @@ -2172,9 +2170,8 @@ babel-plugin-transform-imports@^2.0.0:
"@babel/types" "^7.4"
is-valid-path "^0.1.1"

"babel-plugin-wildcard@github:dword-design/babel-plugin-wildcard#fork":
babel-plugin-wildcard@dword-design/babel-plugin-wildcard#fork:
version "6.0.0"
uid "691d11923ee2dcf63e86f205b0a2c998883e3a3c"
resolved "https://codeload.github.com/dword-design/babel-plugin-wildcard/tar.gz/691d11923ee2dcf63e86f205b0a2c998883e3a3c"
dependencies:
rimraf "^2.6.2"
Expand Down Expand Up @@ -3025,7 +3022,6 @@ [email protected]:

dedent@dword-design/dedent#fork:
version "0.7.0"
uid c8d46e5017d60504657c2d01b59082c0329a12a7
resolved "https://codeload.github.com/dword-design/dedent/tar.gz/c8d46e5017d60504657c2d01b59082c0329a12a7"
dependencies:
babel-plugin-add-module-exports "^1.0.2"
Expand Down Expand Up @@ -3150,9 +3146,8 @@ depcheck-parser-babel@^1.2.0:
"@babel/core" "^7.7.7"
fs-extra "^9.0.0"

"depcheck@github:dword-design/depcheck#fork":
depcheck@dword-design/depcheck#fork:
version "0.0.1"
uid "8a9eb41006c2c6f9cbd79e4e68bf265e1c1df1dc"
resolved "https://codeload.github.com/dword-design/depcheck/tar.gz/8a9eb41006c2c6f9cbd79e4e68bf265e1c1df1dc"
dependencies:
"@babel/parser" "^7.8.4"
Expand Down Expand Up @@ -3322,9 +3317,8 @@ end-of-stream@^1.1.0, end-of-stream@^1.4.1:
dependencies:
once "^1.4.0"

"endent@github:dword-design/endent#fork":
endent@dword-design/endent#fork:
version "1.4.0"
uid be5433db67eaec07c6c9d00ba3bed2ed946dc664
resolved "https://codeload.github.com/dword-design/endent/tar.gz/be5433db67eaec07c6c9d00ba3bed2ed946dc664"
dependencies:
dedent dword-design/dedent#fork
Expand Down Expand Up @@ -3762,9 +3756,8 @@ expect-mocha-image-snapshot@^1.0.0:
jest-image-snapshot "^4.4.0"
jest-snapshot "^26.6.2"

"expect-mocha-snapshot@github:dword-design/expect-mocha-snapshot#fork":
expect-mocha-snapshot@dword-design/expect-mocha-snapshot#fork:
version "2.0.1"
uid f5d168a871ef9073f1b56046dbf875aca6eff1db
resolved "https://codeload.github.com/dword-design/expect-mocha-snapshot/tar.gz/f5d168a871ef9073f1b56046dbf875aca6eff1db"
dependencies:
expect "^1.20.2"
Expand Down

0 comments on commit e989d26

Please sign in to comment.