-
Notifications
You must be signed in to change notification settings - Fork 3
/
cypressPreprocessor.js
39 lines (35 loc) · 1.11 KB
/
cypressPreprocessor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const ipc = require("node-ipc");
const browserifyPreprocessor = require("@cypress/browserify-preprocessor");
let filesToRerun = [];
const setUpIpcServer = () => {
ipc.config.id = "cypress-rerun-with-app";
ipc.config.retry = 1500;
ipc.config.silent = true;
ipc.serve(function() {
ipc.server.on("message", function(data) {
ipc.log("got a message : ".debug, data);
filesToRerun.forEach(file => file.emit("rerun"));
});
ipc.server.on("socket.disconnected", function(socket, destroyedSocketID) {
ipc.log("client " + destroyedSocketID + " has disconnected!");
});
});
ipc.server.start();
};
setUpIpcServer();
const watchApp = preprocessor => file => {
if (!filesToRerun.find(f => f.filePath === file.filePath)) {
filesToRerun.push(file);
file.on("close", () => {
console.log("closing!", file.filePath);
filesToRerun = filesToRerun.filter(f => f.filePath !== file.filePath);
});
}
if (!preprocessor) {
preprocessor = browserifyPreprocessor(
browserifyPreprocessor.defaultOptions
);
}
return preprocessor(file);
};
module.exports = watchApp;