diff --git a/.babelrc b/.babelrc deleted file mode 100644 index a29ac99..0000000 --- a/.babelrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "presets": [ - "@babel/preset-env" - ] -} diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index d9d037f..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,27 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: circleci/node:14 - working_directory: ~/repo - steps: - - checkout - - restore_cache: - name: Restore cached deps - keys: - - v1-dependencies-{{ checksum "package.json" }} - - v1-dependencies- - - run: - name: Install deps - command: yarn install - - save_cache: - name: Save deps to cache - key: v1-dependencies-{{ checksum "package.json" }} - paths: - - node_modules - - run: - name: Tests - command: yarn test - - run: - name: Linter - command: yarn lint diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..1faaa03 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,20 @@ +name: ci + +on: push + +jobs: + ci: + name: CI + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + cache: 'yarn' + - name: Install + run: yarn install + - name: Lint + run: yarn lint + - name: Test + run: yarn test diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..a79d119 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,3 @@ +module.exports = { + presets: ['@babel/preset-env'], +}; diff --git a/example/specific.snapshot.old-format.test.js b/example/specific.snapshot.old-format.test.js new file mode 100644 index 0000000..8b640e6 --- /dev/null +++ b/example/specific.snapshot.old-format.test.js @@ -0,0 +1,9 @@ +import '../src/index'; + +test('test object serialization format', () => { + const object = { + array: [{ hello: 'Danger' }], + }; + + expect(object).toMatchSpecificSnapshot('./specific/strings/strings-old-format.shot'); +}); diff --git a/example/specific.snapshot.test.js b/example/specific.snapshot.test.js index 40beae3..386db98 100644 --- a/example/specific.snapshot.test.js +++ b/example/specific.snapshot.test.js @@ -35,3 +35,11 @@ test('with custom serializer', () => { test('with extended matcher', () => { expect(11).toMatchExtendedSpecificSnapshot('./specific/extended_matcher/test1.shot'); }); + +test('test object serialization format', () => { + const object = { + array: [{ hello: 'Danger' }], + }; + + expect(object).toMatchSpecificSnapshot('./specific/strings/strings.shot'); +}); diff --git a/example/specific/strings/strings-old-format.shot b/example/specific/strings/strings-old-format.shot new file mode 100644 index 0000000..f34ef84 --- /dev/null +++ b/example/specific/strings/strings-old-format.shot @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`test object serialization format 1`] = ` +Object { + "array": Array [ + Object { + "hello": "Danger", + }, + ], +} +`; diff --git a/example/specific/strings/strings.shot b/example/specific/strings/strings.shot new file mode 100644 index 0000000..f0ae4a9 --- /dev/null +++ b/example/specific/strings/strings.shot @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`test object serialization format 1`] = ` +{ + "array": [ + { + "hello": "Danger", + }, + ], +} +`; diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..bcc6a79 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,3 @@ +module.exports = { + cacheDirectory: './.jest/cache', +}; diff --git a/jest.old-format.config.js b/jest.old-format.config.js new file mode 100644 index 0000000..6850266 --- /dev/null +++ b/jest.old-format.config.js @@ -0,0 +1,7 @@ +module.exports = { + cacheDirectory: './.jest/cache', + snapshotFormat: { + escapeString: true, + printBasicPrototype: true, + }, +}; diff --git a/package.json b/package.json index b09792f..99e6c91 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,18 @@ { "name": "jest-specific-snapshot", - "version": "7.0.0", + "version": "8.0.0", "license": "MIT", "repository": "https://github.com/igor-dv/jest-specific-snapshot", "main": "dist/index.js", "scripts": { - "test": "jest specific.snapshot.test", + "test:default": "jest specific.snapshot.test", + "test:old": "jest specific.snapshot.old-format.test --config jest.old-format.config.js", + "test": "npm run test:default && npm run test:old", "babel": "babel src -d dist", "lint": "eslint .", "lint-fix": "npm run lint -- --fix", "prepare": "npm run babel" }, - "jest": { - "cacheDirectory": "./.jest/cache" - }, "dependencies": { "jest-snapshot": "^29.0.0" }, diff --git a/src/index.js b/src/index.js index 4d06233..830cd55 100644 --- a/src/index.js +++ b/src/index.js @@ -42,6 +42,7 @@ function toMatchSpecificSnapshot(received, snapshotFile, ...rest) { snapshotState = new SnapshotState(absoluteSnapshotFile, { updateSnapshot: commonSnapshotState._updateSnapshot, snapshotPath: absoluteSnapshotFile, + snapshotFormat: commonSnapshotState.snapshotFormat, }); snapshotsStateMap.set(absoluteSnapshotFile, snapshotState); } diff --git a/yarn.lock b/yarn.lock index d230093..8218262 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1661,9 +1661,9 @@ camelcase@^6.2.0: integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== caniuse-lite@^1.0.30001219: - version "1.0.30001246" - resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001246.tgz" - integrity sha512-Tc+ff0Co/nFNbLOrziBXmMVtpt9S2c2Y+Z9Nk9Khj09J+0zR9ejvIW5qkZAErCbOrVODCx/MN+GpB5FNBs5GFA== + version "1.0.30001460" + resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001460.tgz" + integrity sha512-Bud7abqjvEjipUkpLs4D7gR0l8hBYBHoa+tGtKJHvT2AYzLp1z7EmVkUT4ERpVUfca8S2HGIVs883D8pUH1ZzQ== chalk@^2.0.0, chalk@^2.1.0: version "2.4.2"