Skip to content

Commit

Permalink
Cypress 12 (#36)
Browse files Browse the repository at this point in the history
* Implement verification before starting the process

* Release 3.4.1-beta.0

* Release 3.4.1-beta.1

* Release 3.4.1
  • Loading branch information
agoldis authored Dec 10, 2022
1 parent 76768d1 commit 68e4c5d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [3.4.1](https://github.com/sorry-cypress/cy2/compare/v3.4.1-beta.1...v3.4.1) (2022-12-10)

## [3.4.1-beta.1](https://github.com/sorry-cypress/cy2/compare/v3.4.1-beta.0...v3.4.1-beta.1) (2022-12-10)

## [3.4.1-beta.0](https://github.com/sorry-cypress/cy2/compare/v3.4.0...v3.4.1-beta.0) (2022-12-10)

# [3.4.0](https://github.com/sorry-cypress/cy2/compare/v3.3.0...v3.4.0) (2022-12-10)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cy2",
"version": "3.4.0",
"version": "3.4.1",
"author": "Andrew Goldis",
"main": "./dist",
"typings": "./dist",
Expand Down
5 changes: 2 additions & 3 deletions src/__tests__/ast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const result = (path = 'foo') => `(function ${FN_ID}() {
try {
require('${path}')('source', 'backup');
} catch (e) {
console.error(e);
}
}());
process.env.CYPRESS_INTERNAL_ENV = process.env.CYPRESS_INTERNAL_ENV || 'production';
Expand Down Expand Up @@ -65,9 +66,7 @@ test('should inject new code for windows path', async () => {
).toEqual(
result(
normalizePath(
'C:\\Users\\Administrator\\Desktop\\node_modules\\cy2\\dist/injected.js',
'source',
'backup'
'C:\\Users\\Administrator\\Desktop\\node_modules\\cy2\\dist/injected.js'
)
)
);
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const run = async (label: string = 'cy2') => {
console.log(
`[${label}] Running cypress with API URL: ${process.env.CYPRESS_API_URL}`
);
await lib.verify();
await lib.patchServerInit(`${__dirname}/injected.js`);
const childProcess = await lib.run();
childProcess.on('exit', (code) => process.exit(code ?? 1));
Expand Down
4 changes: 3 additions & 1 deletion src/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export const instrumentCypressInit = (
const injectedFn = `
function ${FN_ID}() {
try { require('${normalizedPath}')("${entryPointPath}", "${backupPath}"); }
catch (e) {}
catch (e) {
console.error(e);
}
}`;

const injectedCode = `(${injectedFn})();`;
Expand Down
8 changes: 8 additions & 0 deletions src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export async function patchServerInit(injectedAbsolutePath: string) {
debug('Patching cypress entry point file: %s', serverInitPath);

const serverInitBackup = serverInitPath + '.bak';

if (!pathExists(serverInitBackup)) {
fs.copyFileSync(serverInitPath, serverInitBackup);
}
Expand All @@ -27,6 +28,7 @@ export async function patchServerInit(injectedAbsolutePath: string) {
serverInitPath,
serverInitBackup
);

fs.writeFileSync(serverInitPath, result);
}

Expand Down Expand Up @@ -77,3 +79,9 @@ export async function run() {
debug('Running cypress from %s', cliBinPath, ...rest);
return cp.spawn(cliBinPath, [...rest], { stdio: 'inherit' });
}

export async function verify() {
const cliBinPath = await getCypressCLIBinPath();
debug('Verifying cypress from %s', cliBinPath);
cp.execFileSync(cliBinPath, ['verify'], { stdio: 'pipe' });
}

0 comments on commit 68e4c5d

Please sign in to comment.