regressify 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,8 +5,9 @@ on:
5
5
  branches:
6
6
  - release
7
7
  paths:
8
- - src/**
9
8
  - .engine_scripts/**
9
+ - src/**
10
+ - package.json
10
11
 
11
12
  workflow_dispatch:
12
13
 
package/README.md CHANGED
@@ -7,19 +7,21 @@ Please check [Documentation](https://tuyen.blog/optimizely-cms/testing/get-start
7
7
  1. Install:
8
8
 
9
9
  ```bash
10
- npm i @eshn/visual-regression-tests
10
+ npm i regressify
11
11
  ```
12
12
 
13
13
  1. Manual Set up all test and config files in the **visual_tests** folder and place it at the root of the project, or automatically add it using the command:
14
+
14
15
  ```bash
15
- npx eshn-visual generate
16
+ npx regressify-cli init
16
17
  ```
18
+
17
19
  1. Add to scripts in package.json:
18
20
 
19
21
  ```bash
20
- "ref": "eshn-visual ref",
21
- "approve": "eshn-visual approve",
22
- "test": "eshn-visual test"
22
+ "ref": "regressify-cli ref",
23
+ "approve": "regressify-cli approve",
24
+ "test": "regressify-cli test"
23
25
  ```
24
26
 
25
27
  1. Use new command aliases:
package/approve.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import chalk from 'chalk';
3
+ import { runCommand } from './helpers';
4
+
5
+ const args = process.argv.slice(2);
6
+ let commandBase = `tsx ${getLibraryPath()}/src/index.ts`;
7
+
8
+ const command = `${commandBase} --command approve ${args.slice(1).join(' ')}`;
9
+ console.log(chalk.yellow(`Running command: ${command}`));
10
+ runCommand(command);
package/helpers.ts ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'fs';
3
+ import path, { dirname } from 'path';
4
+ import { exec } from 'child_process';
5
+ import { fileURLToPath, pathToFileURL } from 'url';
6
+ import chalk from 'chalk';
7
+
8
+ export function getLibraryPath() {
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = dirname(__filename);
11
+
12
+ let currentDir = __dirname;
13
+ while (!fs.existsSync(path.join(currentDir, 'package.json'))) {
14
+ const parentDir = path.dirname(currentDir);
15
+ if (parentDir === currentDir) {
16
+ return null;
17
+ }
18
+ currentDir = parentDir;
19
+ }
20
+ const packageJsonPath = path.join(currentDir, 'package.json');
21
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
22
+ return `node_modules/${packageJson.name}`;
23
+ }
24
+
25
+ export function runCommand(command) {
26
+ const childProcess = exec(command, { env: { ...process.env, FORCE_COLOR: '1' } });
27
+
28
+ if (!childProcess) {
29
+ console.log(chalk.red('Failed to start command'));
30
+ return;
31
+ }
32
+
33
+ if (!childProcess.stdout) {
34
+ console.log(chalk.red('Failed to get stdout'));
35
+ return;
36
+ }
37
+
38
+ if (!childProcess.stderr) {
39
+ console.log(chalk.red('Failed to get stderr'));
40
+ return;
41
+ }
42
+
43
+ childProcess.stdout.on('data', (data) => {
44
+ process.stdout.write(data);
45
+ });
46
+
47
+ childProcess.stderr.on('data', (data) => {
48
+ process.stderr.write(data);
49
+ });
50
+
51
+ childProcess.on('close', (code) => {
52
+ if (code !== 0) {
53
+ console.log(chalk.red(`Command exited with code ${code}`));
54
+ }
55
+ });
56
+
57
+ childProcess.on('error', (err) => {
58
+ console.log(chalk.red(`Failed to start command: ${err.message}`));
59
+ });
60
+ }
package/init.js ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'fs';
3
+ import path, { dirname } from 'path';
4
+ import { fileURLToPath, pathToFileURL } from 'url';
5
+ import chalk from 'chalk';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = dirname(__filename);
9
+ const postInstallPath = pathToFileURL(path.join(__dirname, 'generate_tests.js'));
10
+ if (fs.existsSync(postInstallPath)) {
11
+ console.log(chalk.yellow('generate folder visual_tests ...'));
12
+ await import(postInstallPath);
13
+ } else {
14
+ console.log(chalk.red('generate_tests.js not found!'));
15
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "regressify",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Visual regression tests support",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "bin": {
8
- "eshn-visual": "./cli.js"
8
+ "regressify": "./cli.js"
9
9
  },
10
10
  "scripts": {
11
11
  "ref": "tsx src/index.ts --command test --ref",
package/ref.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import chalk from 'chalk';
3
+
4
+ const args = process.argv.slice(2);
5
+ let commandBase = `tsx ${getLibraryPath()}/src/index.ts`;
6
+
7
+ const command = `${commandBase} --command test --ref ${args.slice(1).join(' ')}`;
8
+ console.log(chalk.yellow(`Running command: ${command}`));
package/test.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import chalk from 'chalk';
3
+
4
+ const args = process.argv.slice(2);
5
+ let commandBase = `tsx ${getLibraryPath()}/src/index.ts`;
6
+
7
+ const command = `${commandBase} --command test ${args.slice(1).join(' ')}`;
8
+ console.log(chalk.yellow(`Running command: ${command}`));
9
+ runCommand(command);