Run tests in pre-commit
This commit is contained in:
1
.husky/pre-commit
Normal file
1
.husky/pre-commit
Normal file
@@ -0,0 +1 @@
|
|||||||
|
npm test
|
||||||
21
package-lock.json
generated
21
package-lock.json
generated
@@ -1,18 +1,19 @@
|
|||||||
{
|
{
|
||||||
"name": "envsitter",
|
"name": "envsitter",
|
||||||
"version": "0.1.0",
|
"version": "0.0.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "envsitter",
|
"name": "envsitter",
|
||||||
"version": "0.1.0",
|
"version": "0.0.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bin": {
|
"bin": {
|
||||||
"envsitter": "dist/cli.js"
|
"envsitter": "dist/cli.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.10.2",
|
"@types/node": "^22.10.2",
|
||||||
|
"husky": "^9.1.7",
|
||||||
"typescript": "^5.7.3"
|
"typescript": "^5.7.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -26,6 +27,22 @@
|
|||||||
"undici-types": "~6.21.0"
|
"undici-types": "~6.21.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/husky": {
|
||||||
|
"version": "9.1.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz",
|
||||||
|
"integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"husky": "bin.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/typicode"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/typescript": {
|
"node_modules/typescript": {
|
||||||
"version": "5.9.3",
|
"version": "5.9.3",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||||
|
|||||||
@@ -20,10 +20,12 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc -p tsconfig.json",
|
"build": "tsc -p tsconfig.json",
|
||||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||||
"test": "npm run build && node scripts/run-tests.mjs"
|
"test": "npm run build && node scripts/run-tests.mjs",
|
||||||
|
"prepare": "husky"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.10.2",
|
"@types/node": "^22.10.2",
|
||||||
|
"husky": "^9.1.7",
|
||||||
"typescript": "^5.7.3"
|
"typescript": "^5.7.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,14 +20,27 @@ test('resolvePepper reads from env when set', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('resolvePepper creates a pepper file when missing', async () => {
|
test('resolvePepper creates a pepper file when missing', async () => {
|
||||||
const dir = await mkdtemp(join(tmpdir(), 'envsitter-'));
|
const prevEnvSitterPepper = process.env.ENVSITTER_PEPPER;
|
||||||
const pepperPath = join(dir, 'pepper');
|
const prevEnvSitterPepperAlt = process.env.ENV_SITTER_PEPPER;
|
||||||
|
delete process.env.ENVSITTER_PEPPER;
|
||||||
|
delete process.env.ENV_SITTER_PEPPER;
|
||||||
|
|
||||||
const pepper = await resolvePepper({ pepperFilePath: pepperPath });
|
try {
|
||||||
assert.equal(pepper.source, 'file');
|
const dir = await mkdtemp(join(tmpdir(), 'envsitter-'));
|
||||||
assert.equal(pepper.pepperFilePath, pepperPath);
|
const pepperPath = join(dir, 'pepper');
|
||||||
assert.ok(pepper.pepperBytes.length >= 16);
|
|
||||||
|
|
||||||
const persisted = (await readFile(pepperPath, 'utf8')).trim();
|
const pepper = await resolvePepper({ pepperFilePath: pepperPath });
|
||||||
assert.ok(persisted.length > 0);
|
assert.equal(pepper.source, 'file');
|
||||||
|
assert.equal(pepper.pepperFilePath, pepperPath);
|
||||||
|
assert.ok(pepper.pepperBytes.length >= 16);
|
||||||
|
|
||||||
|
const persisted = (await readFile(pepperPath, 'utf8')).trim();
|
||||||
|
assert.ok(persisted.length > 0);
|
||||||
|
} finally {
|
||||||
|
if (prevEnvSitterPepper === undefined) delete process.env.ENVSITTER_PEPPER;
|
||||||
|
else process.env.ENVSITTER_PEPPER = prevEnvSitterPepper;
|
||||||
|
|
||||||
|
if (prevEnvSitterPepperAlt === undefined) delete process.env.ENV_SITTER_PEPPER;
|
||||||
|
else process.env.ENV_SITTER_PEPPER = prevEnvSitterPepperAlt;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user