Simple test to ensure that all dependencies have a pinned version

Created Oct 8 2020

JS
1
const packageJson = require("../package.json");
2
3
describe("Dependencies", () => {
4
// Reference https://gist.github.com/jhorsman/62eeea161a13b80e39f5249281e17c39
5
const semverRegex = /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?$/;
6
7
it("Ensures all dependencies have a pinned version", () => {
8
Object.values(packageJson.dependencies).forEach((version) => {
9
expect(version).toMatch(semverRegex);
10
});
11
});
12
13
it("Ensures all dev dependencies have a pinned version", () => {
14
Object.values(packageJson.devDependencies).forEach((version) => {
15
expect(version).toMatch(semverRegex);
16
});
17
});
18
});