-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_modules
More file actions
70 lines (60 loc) · 2.37 KB
/
node_modules
File metadata and controls
70 lines (60 loc) · 2.37 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
.gitignore
```
```javascript
// scripts/version_check.js
const fs = require('fs');
const path = require('path');
function verifyPackageVersions() {
const packageJsonPath = path.join(__dirname, '..', 'package.json'); // Path to package.json
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
const dependencies = packageJson.dependencies;
let hasMismatches = false;
const checkVersion = (packageName, expectedVersion) => {
try {
const modulePath = path.join(__dirname, '..', 'node_modules', packageName, 'package.json');
const modulePackageJson = JSON.parse(fs.readFileSync(modulePath, 'utf-8'));
const installedVersion = modulePackageJson.version;
if (installedVersion !== expectedVersion) {
console.error(`Version mismatch for ${packageName}. Expected: ${expectedVersion}, Installed: ${installedVersion}`);
hasMismatches = true;
} else {
console.log(`Version check passed for ${packageName}: ${installedVersion}`);
}
} catch (error) {
console.error(`Could not verify version for ${packageName}: ${error.message}`);
hasMismatches = true;
}
};
for (const packageName in dependencies) {
if (dependencies.hasOwnProperty(packageName)) {
checkVersion(packageName, dependencies[packageName]);
}
}
if (hasMismatches) {
console.error('Version verification failed. Please update your dependencies.');
process.exit(1); // Exit with a non-zero code to indicate failure
} else {
console.log('All dependency versions verified successfully.');
process.exit(0); // Exit with a zero code to indicate success
}
}
verifyPackageVersions();
```
```javascript
// scripts/test/version_check_test.js
const { execSync } = require('child_process');
const path = require('path');
describe('Version Check Script', () => {
it('should pass the version check for three', () => {
const scriptPath = path.join(__dirname, '..', 'version_check.js');
try {
const result = execSync(`node ${scriptPath}`, { encoding: 'utf-8' });
expect(result).toContain('Version check passed for three');
} catch (error) {
// If the script fails (exits with a non-zero code), the error object will contain the output
console.error('Script execution failed:', error);
// Fail the test if the script does not pass
expect(error).toBeNull();
}
}, 60000);
});