Comparing version 3.3.0 to 3.4.0
@@ -0,1 +1,2 @@ | ||
export declare function pathExists(path: string): boolean; | ||
export declare const lookupPaths: (candidates?: string[]) => string | undefined; |
@@ -5,2 +5,3 @@ "use strict"; | ||
}); | ||
exports.pathExists = pathExists; | ||
exports.lookupPaths = void 0; | ||
@@ -7,0 +8,0 @@ var _fs = _interopRequireDefault(require("fs")); |
@@ -1,2 +0,1 @@ | ||
declare const Mod: any; | ||
declare const req: any; | ||
export {}; |
"use strict"; | ||
var _fs = require("fs"); | ||
var ref, ref1; | ||
@@ -6,5 +7,2 @@ const Mod = require('module'); | ||
// @ts-ignore | ||
global.integrityCheck = function() { | ||
}; | ||
// @ts-ignore | ||
if ((ref = global.snapshotResult) === null || ref === void 0 ? void 0 : (ref1 = ref.customRequire) === null || ref1 === void 0 ? void 0 : ref1.exports) { | ||
@@ -60,1 +58,4 @@ // @ts-ignore | ||
}; | ||
module.exports = function(entryPointPath, backupPath) { | ||
(0, _fs).copyFileSync(backupPath, entryPointPath); | ||
}; |
@@ -5,3 +5,3 @@ import { Program } from 'estree'; | ||
export declare const FN_ID = "cy2_injected"; | ||
export declare const instrumentCypressInit: (code: string, injectedModulePath: string) => any; | ||
export declare const instrumentCypressInit: (code: string, injectedModulePath: string, entryPointPath: string, backupPath: string) => any; | ||
export declare function hasInjected(ast: Program): boolean; |
@@ -26,7 +26,7 @@ "use strict"; | ||
exports.FN_ID = FN_ID; | ||
const instrumentCypressInit = (code, injectedModulePath)=>{ | ||
const instrumentCypressInit = (code, injectedModulePath, entryPointPath, backupPath)=>{ | ||
const normalizedPath = (0, _path).normalizePath(injectedModulePath); | ||
const injectedFn = ` | ||
function ${FN_ID}() { | ||
try { require('${normalizedPath}'); } | ||
try { require('${normalizedPath}')("${entryPointPath}", "${backupPath}"); } | ||
catch (e) {} | ||
@@ -68,3 +68,4 @@ }`; | ||
enter: function(node) { | ||
if (node.type == _estraverse.default.Syntax.FunctionExpression && node.id.name === FN_ID) { | ||
var ref; | ||
if (node.type == _estraverse.default.Syntax.FunctionExpression && ((ref = node.id) === null || ref === void 0 ? void 0 : ref.name) === FN_ID) { | ||
return injectedFnAst.body[0]; | ||
@@ -71,0 +72,0 @@ } |
@@ -10,3 +10,2 @@ "use strict"; | ||
var _fs = _interopRequireDefault(require("fs")); | ||
var _js = require("./js"); | ||
var _jsYaml = _interopRequireDefault(require("js-yaml")); | ||
@@ -16,2 +15,4 @@ var _binPath = require("./bin-path"); | ||
var _discovery = require("./discovery"); | ||
var _fs1 = require("./fs"); | ||
var _js = require("./js"); | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
@@ -55,4 +56,8 @@ try { | ||
(0, _debug).debug('Patching cypress entry point file: %s', serverInitPath); | ||
const serverInitBackup = serverInitPath + '.bak'; | ||
if (!(0, _fs1).pathExists(serverInitBackup)) { | ||
_fs.default.copyFileSync(serverInitPath, serverInitBackup); | ||
} | ||
const doc = _fs.default.readFileSync(serverInitPath, 'utf8'); | ||
const result = (0, _js).instrumentCypressInit(doc, injectedAbsolutePath); | ||
const result = (0, _js).instrumentCypressInit(doc, injectedAbsolutePath, serverInitPath, serverInitBackup); | ||
_fs.default.writeFileSync(serverInitPath, result); | ||
@@ -59,0 +64,0 @@ }); |
{ | ||
"name": "cy2", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"author": "Andrew Goldis", | ||
@@ -5,0 +5,0 @@ "main": "./dist", |
48949
1169
23