regressify 1.0.1 → 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.
- package/.github/workflows/deploy.yml +2 -1
- package/README.md +1 -1
- package/approve.js +0 -0
- package/cli.js +76 -0
- package/init.js +0 -0
- package/package.json +2 -5
- package/ref.js +0 -0
- package/test.js +0 -0
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Please check [Documentation](https://tuyen.blog/optimizely-cms/testing/get-start
|
|
|
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
15
|
```bash
|
|
16
|
-
npx regressify-cli
|
|
16
|
+
npx regressify-cli init
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
1. Add to scripts in package.json:
|
package/approve.js
CHANGED
|
File without changes
|
package/cli.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
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
|
+
function runCommand(command) {
|
|
26
|
+
const childProcess = exec(command, { env: { ...process.env, FORCE_COLOR: '1' } });
|
|
27
|
+
|
|
28
|
+
childProcess.stdout.on('data', (data) => {
|
|
29
|
+
process.stdout.write(data);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
childProcess.stderr.on('data', (data) => {
|
|
33
|
+
process.stderr.write(data);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
childProcess.on('close', (code) => {
|
|
37
|
+
if (code !== 0) {
|
|
38
|
+
console.log(chalk.red(`Command exited with code ${code}`));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
childProcess.on('error', (err) => {
|
|
43
|
+
console.log(chalk.red(`Failed to start command: ${err.message}`));
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const args = process.argv.slice(2);
|
|
48
|
+
let commandBase = `tsx ${getLibraryPath()}/src/index.ts`;
|
|
49
|
+
|
|
50
|
+
if (args[0] === 'generate') {
|
|
51
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
52
|
+
const __dirname = dirname(__filename);
|
|
53
|
+
const postInstallPath = pathToFileURL(path.join(__dirname, 'generate_tests.js'));
|
|
54
|
+
if (fs.existsSync(postInstallPath)) {
|
|
55
|
+
console.log(chalk.yellow('generate folder visual_tests ...'));
|
|
56
|
+
await import(postInstallPath);
|
|
57
|
+
} else {
|
|
58
|
+
console.log(chalk.red('generate_tests.js not found!'));
|
|
59
|
+
}
|
|
60
|
+
} else if (args[0] === 'ref') {
|
|
61
|
+
const command = `${commandBase} --command test --ref ${args.slice(1).join(' ')}`;
|
|
62
|
+
console.log(chalk.yellow(`Running command: ${command}`));
|
|
63
|
+
runCommand(command);
|
|
64
|
+
} else if (args[0] === 'approve') {
|
|
65
|
+
const command = `${commandBase} --command approve ${args.slice(1).join(' ')}`;
|
|
66
|
+
console.log(chalk.yellow(`Running command: ${command}`));
|
|
67
|
+
runCommand(command);
|
|
68
|
+
} else if (args[0] === 'test') {
|
|
69
|
+
const command = `${commandBase} --command test ${args.slice(1).join(' ')}`;
|
|
70
|
+
console.log(chalk.yellow(`Running command: ${command}`));
|
|
71
|
+
runCommand(command);
|
|
72
|
+
} else {
|
|
73
|
+
console.log(
|
|
74
|
+
chalk.red("Invalid command. Use one of the following: 'eshn-visual generate' 'eshn-visual ref', 'eshn-visual approve', 'eshn-visual test'.")
|
|
75
|
+
);
|
|
76
|
+
}
|
package/init.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "regressify",
|
|
3
|
-
"version": "1.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
|
-
"
|
|
9
|
-
"ref": "./ref.js",
|
|
10
|
-
"test": "./test.js",
|
|
11
|
-
"approve": "./approve.js"
|
|
8
|
+
"regressify": "./cli.js"
|
|
12
9
|
},
|
|
13
10
|
"scripts": {
|
|
14
11
|
"ref": "tsx src/index.ts --command test --ref",
|
package/ref.js
CHANGED
|
File without changes
|
package/test.js
CHANGED
|
File without changes
|