Skip to content

Commit 2af9932

Browse files
committed
test(version): add check for packages field version in package-lock.json
The previous test only checked packageLockJson.version at the root level, but missed the version field inside packageLockJson.packages['']. This update adds validation for: - packageLockJson.packages[''].version matches package.json version - packageLockJson.packages[''].name matches package.json name This ensures all version fields in package-lock.json are consistent with package.json. Change-Id: I3e0423cf84ab202d997ea9431b69a99e82a3641d Co-developed-by: Claude <noreply@anthropic.com>
1 parent 13b6743 commit 2af9932

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

test/version.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { describe, it, expect } from 'vitest';
22
import { execSync } from 'child_process';
3+
import { readFileSync } from 'fs';
4+
import { join, dirname } from 'path';
5+
import { fileURLToPath } from 'url';
36

47
// Check Node.js version to determine which dev script to use
58
// Node.js 22+ and 20: Use tsx (dev and dev:node20 respectively)
@@ -162,4 +165,30 @@ describe('commit-msg CLI version tests', () => {
162165
}
163166
}
164167
});
168+
169+
// Test that package.json and package-lock.json versions are in sync
170+
it('should have consistent version in package.json and package-lock.json', () => {
171+
const __dirname = dirname(fileURLToPath(import.meta.url));
172+
const rootDir = join(__dirname, '..');
173+
const packageJsonPath = join(rootDir, 'package.json');
174+
const packageLockJsonPath = join(rootDir, 'package-lock.json');
175+
176+
// Read and parse package.json
177+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
178+
const packageJsonVersion = packageJson.version;
179+
180+
// Read and parse package-lock.json
181+
const packageLockJson = JSON.parse(
182+
readFileSync(packageLockJsonPath, 'utf-8')
183+
);
184+
const packageLockJsonVersion = packageLockJson.version;
185+
186+
expect(packageJsonVersion).toBe(packageLockJsonVersion);
187+
188+
// Also check the version in packages field (root package entry)
189+
const rootPackage = packageLockJson.packages[''];
190+
expect(rootPackage).toBeDefined();
191+
expect(rootPackage.version).toBe(packageJsonVersion);
192+
expect(rootPackage.name).toBe(packageJson.name);
193+
});
165194
});

0 commit comments

Comments
 (0)