Skip to content

Commit b7de42d

Browse files
author
Meinaart van Straalen
committed
Breaking snapshot functionality when running all tests, previous fix breaks other functionality (Reopens #10) (Fixes #14)
1 parent fbefa8f commit b7de42d

10 files changed

+335
-2196
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html).
55

66
## Releases
7+
### [1.2.5](https://github.com/meinaart/cypress-plugin-snapshots/compare/v1.2.4...v1.2.5) - 2019-01-11
8+
- Breaking snapshot functionality when running all tests, previous fix breaks other functionality (Reopens #10) (Fixes #14)
9+
710
### [1.2.4](https://github.com/meinaart/cypress-plugin-snapshots/compare/v1.2.3...v1.2.4) - 2019-01-04
811
- Fix broken `excludedFields` functionality
912

package-lock.json

+313-2,109
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"test": "jest & npm --prefix cypress run cy:run"
4040
},
4141
"dependencies": {
42-
"@cypress/browserify-preprocessor": "^1.1.2",
4342
"bufferutil": "^4.0.0",
4443
"chalk": "^2.4.1",
4544
"diff2html": "^2.5.0",

plugin.js

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
const { initConfig, CONFIG_KEY } = require('./src/config');
33
const initServer = require('./src/server/initServer');
44
const tasks = require('./src/tasks/');
5-
const initSetSpecInServer = require('./src/plugin/initSetSpecInServer');
65

76
/**
87
* Initializes the plugin:
@@ -15,7 +14,6 @@ function initPlugin(on, globalConfig = {
1514
}) {
1615
const config = initConfig(globalConfig.env[CONFIG_KEY]);
1716
initServer(config);
18-
initSetSpecInServer(on, config);
1917

2018
// Adding sub objects/keys to `Cypress.env` that don't exist in `cypress.json` doesn't work.
2119
// That's why the config is stringified and parsed again in `src/utils/commands/getConfig.js#fixConfig`.

src/plugin/initSetSpecInServer.js

-42
This file was deleted.

src/server/actions.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
module.exports = {
2-
GET_SPEC: 'cypress-plugin-snapshot:getSpec',
32
SAVE_IMAGE: 'cypress-plugin-snapshot:saveImage',
43
SAVE_TEXT: 'cypress-plugin-snapshot:saveText',
5-
SET_SPEC: 'cypress-plugin-snapshot:setSpec',
64
};

src/server/getSpec.js

-12
This file was deleted.

src/server/setSpec.js

-9
This file was deleted.

src/utils/commands/cleanupSnapshots.js

+18-15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { formatNormalizedJson, } = require('../../utils/json');
44
const getTextSnapshotFilename = require('../text/getSnapshotFilename');
55
const { snapshotTitleIsUsed } = require('../../utils/snapshotTitles');
66
const getConfig = require('./getConfig');
7+
const getSpec = require('./getSpec');
78
const { NO_LOG } = require('../../constants');
89

910
// Removes unused snapshots from snapshot file
@@ -13,23 +14,25 @@ function cleanUpSnapshots() {
1314
return;
1415
}
1516

16-
const filename = getTextSnapshotFilename(Cypress.spec.relative);
17-
cy.readFile(filename, NO_LOG).then((content) => {
18-
if (content) {
19-
const snapshot = JSON.parse(content);
20-
const keys = Object.keys(snapshot);
17+
getSpec().then((spec) => {
18+
const filename = getTextSnapshotFilename(spec.relative);
19+
cy.readFile(filename, NO_LOG).then((content) => {
20+
if (content) {
21+
const snapshot = JSON.parse(content);
22+
const keys = Object.keys(snapshot);
2123

22-
const cleanSnapshot = keys
23-
.filter(snapshotTitleIsUsed)
24-
.reduce((result, key) => {
25-
result[key] = snapshot[key];
26-
return result;
27-
}, {});
24+
const cleanSnapshot = keys
25+
.filter(snapshotTitleIsUsed)
26+
.reduce((result, key) => {
27+
result[key] = snapshot[key];
28+
return result;
29+
}, {});
2830

29-
cy.writeFile(filename,
30-
formatNormalizedJson(cleanSnapshot),
31-
NO_LOG);
32-
}
31+
cy.writeFile(filename,
32+
formatNormalizedJson(cleanSnapshot),
33+
NO_LOG);
34+
}
35+
});
3336
});
3437
}
3538

src/utils/commands/getSpec.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
const getSpecFromServer = require('../../server/getSpec');
2-
const getConfig = require('./getConfig');
3-
41
async function getSpec() {
52
if (Cypress.spec.absolute === '__all') {
6-
return getSpecFromServer(getConfig());
3+
throw new Error(`cypress-plugin-snapshots does not work when running all tests, this will be fixed once this bug is resolved: https://github.com/cypress-io/cypress/issues/3090`);
74
}
85

96
return Promise.resolve(Cypress.spec);

0 commit comments

Comments
 (0)