mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-03 12:28:13 +03:00
Add tap-snapshot utility scripts.
This commit is contained in:
Executable
+45
@@ -0,0 +1,45 @@
|
||||
const fs = require("fs");
|
||||
|
||||
// This script takes a path to a .test.ts file, finds its equivalent snapshot file
|
||||
// and merges it with single-process-tap's snapshot file.
|
||||
|
||||
const toMerge = process.argv[2];
|
||||
|
||||
if (!toMerge) {
|
||||
throw new Error("no argv passed to merge-snap. Can't merge with nothing.");
|
||||
}
|
||||
|
||||
const BASE_FILE = "./tap-snapshots/src/test-utils/single-process-tap.ts.test.cjs";
|
||||
const NEW_FILE = `${toMerge.replace("tachi-server/src", "tachi-server/tap-snapshots/src")}.test.cjs`;
|
||||
|
||||
const baseSet = require(BASE_FILE);
|
||||
|
||||
const newSet = require(NEW_FILE);
|
||||
|
||||
for (const [snapshotName, snapshotValue] of Object.entries(newSet)) {
|
||||
baseSet[snapshotName] = snapshotValue;
|
||||
}
|
||||
|
||||
|
||||
function escapeBacktickString(str) {
|
||||
return str.replace(/\`\$/, " ")
|
||||
}
|
||||
|
||||
const cases = [];
|
||||
|
||||
for (const [snapshotName, snapshotValue] of Object.entries(baseSet)) {
|
||||
cases.push(`exports[\`${escapeBacktickString(snapshotName)}\`] = \`${escapeBacktickString(snapshotValue)}\`\n`)
|
||||
}
|
||||
|
||||
let outFile = `
|
||||
/* IMPORTANT
|
||||
* This snapshot file is auto-generated, but designed for humans.
|
||||
* It should be checked into source control and tracked carefully.
|
||||
* Re-generate by setting TAP_SNAPSHOT=1 and running tests.
|
||||
* Make sure to inspect the output below. Do not ignore changes!
|
||||
*/
|
||||
'use strict'
|
||||
${cases.join("\n")}`
|
||||
|
||||
fs.writeFileSync(BASE_FILE, outFile);
|
||||
fs.rmSync(NEW_FILE);
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#! /bin/bash
|
||||
|
||||
# This script is intended to be used as follows
|
||||
# ./snap-single-file.sh path/to/test.TAP_SNAPSHOT
|
||||
# This will result in that individual file being snapped.
|
||||
|
||||
# Of course, we need to do this like this because we are abusing
|
||||
# single process tap to get our tests done faster.
|
||||
|
||||
# Put us in the directory this script is in.
|
||||
cd "$(dirname "$0")" || exit 1
|
||||
|
||||
# So, TAP wont exit when ran on a single file because we never close it.
|
||||
# This can be fixed another time, but until then I'm going to do this insane hack.
|
||||
onsigint()
|
||||
{
|
||||
node ./merge-snap.js "$1"
|
||||
}
|
||||
|
||||
# When we recieve a sigint, trap it and call our sigint handler.
|
||||
# of course, this is bash, so trap onsigint doesn't do what you want.
|
||||
# instead, we do 'onsigint "$@"', which means call onsigint with arguments like $1.
|
||||
trap 'onsigint "$@"' SIGINT
|
||||
|
||||
# Snapshot the argument.
|
||||
TAP_SNAPSHOT=1 tap "$1"
|
||||
|
||||
Reference in New Issue
Block a user