Skip to content

Commit

Permalink
chore: do not update schema hash during tests or ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Coobaha committed Nov 4, 2023
1 parent 71d358a commit 5103dd9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion generator/gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import traverse from 'json-schema-traverse';
import mergeAllOf from 'json-schema-merge-allof';
import type { JSONSchema7 } from 'json-schema';
import { JSONSchema7Definition } from 'json-schema';
import { isCI, isTest } from 'std-env';

const doNotUpdateHash = isCI || isTest;
const revision = '__v' + require('../package.json').version; // + Date.now();

async function normalizeSchema(originalSchema: JSONSchema7, rootId: string, newRootId: string) {
Expand Down Expand Up @@ -148,10 +150,13 @@ export default async (params: { files: string[] }) => {
const contents = await fs.readFile(file, 'utf-8');
const saved = `${dir}/${name}.gen.json`;
const savedExists = nodeFs.existsSync(saved);
const $hash = sha256(contents).toString() + revision;
let $hash = sha256(contents).toString() + revision;
try {
if (savedExists) {
const existing = JSON.parse(await fs.readFile(saved, 'utf-8'));
if (doNotUpdateHash) {
$hash = existing.$hash;
}
if (existing.$hash === $hash) {
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"pinst": "^3.0.0",
"prettier": "^3.0.3",
"split2": "^4.2.0",
"std-env": "3.4.3",
"syncpack": "^11.2.1",
"tap": "^16.3.8",
"ts-node-dev": "^2.0.0",
Expand Down Expand Up @@ -80,7 +81,7 @@
"preserver": "tsnd generator/gen.bin.ts gen 'test/test_schema.ts'",
"pretest": "tsnd generator/gen.bin.ts gen 'test/test_schema.ts'",
"server": "pnpm preserver && tsnd test/server.ts",
"test": "pnpm pretest && pnpm test:types && pnpm test:integration",
"test": "NODE_ENV=test pnpm pretest && pnpm test:types && pnpm test:integration",
"test:integration": "TAP_TS=1 tap test/*.test.ts -R dot",
"test:types": "tsc -p test/tsconfig.test.json"
}
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5103dd9

Please sign in to comment.