-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
29 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,47 @@ | ||
import { exec } from 'child_process'; | ||
import fs from 'fs'; | ||
import { spawnSync } from 'child_process'; | ||
import assert from 'assert'; | ||
import * as util from 'util'; | ||
const execAsync = util.promisify(exec); | ||
|
||
async function main() { | ||
const hash = 'e250bec'; | ||
const snapshotPath = `${hash}.snapshot`; | ||
const { stdout, stderr } = await execAsync( | ||
`git show ${hash} | node ./build/index.mjs --color` | ||
const input = ` | ||
commit e250bec66b6c39d4c2f9e0e52a18245f16a7195a | ||
Author: Shrey Banga <banga.shrey@gmail.com> | ||
Date: Fri Dec 29 11:14:25 2023 -0500 | ||
Exclude lockfiles from diffs | ||
diff --git a/.gitattributes b/.gitattributes | ||
new file mode 100644 | ||
index 0000000..c72d334 | ||
--- /dev/null | ||
+++ b/.gitattributes | ||
@@ -0,0 +1,3 @@ | ||
+# exclude lock files from git diff | ||
+package-lock.json -diff | ||
+yarn.lock -diff | ||
`; | ||
const expected = ` | ||
[48;2;43;43;43m[38;2;136;192;208mcommit[39m[49m[48;2;43;43;43m[38;2;191;97;106m e250bec66b6c39d4c2f9e0e52a18245f16a7195a [39m[49m[48;2;43;43;43m[38;2;76;86;106m [39m[49m | ||
[48;2;43;43;43m[38;2;136;192;208mAuthor:[39m[49m[48;2;43;43;43m[38;2;208;135;112m Shrey Banga <banga.shrey@gmail.com> [39m[49m[48;2;43;43;43m[38;2;76;86;106m [39m[49m | ||
[48;2;43;43;43m[38;2;136;192;208mDate:[39m[49m[48;2;43;43;43m[38;2;235;203;139m Fri Dec 29 11:14:25 2023 -0500 [39m[49m[48;2;43;43;43m[38;2;76;86;106m [39m[49m | ||
[48;2;43;43;43m[38;2;76;86;106m [39m[49m | ||
[48;2;43;43;43m[38;2;236;239;244m Exclude lockfiles from diffs[39m[49m[48;2;43;43;43m[38;2;216;222;233m [39m[49m | ||
[48;2;43;43;43m[38;2;216;222;233m [39m[49m | ||
[48;2;43;43;43m[38;2;235;203;139m──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────[39m[49m | ||
[48;2;43;43;43m[38;2;235;203;139m [39m[49m[48;2;48;58;53m[38;2;163;190;140m■■[39m[49m[48;2;43;43;43m[38;2;235;203;139m .gitattributes [39m[49m | ||
[48;2;43;43;43m[38;2;235;203;139m──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────[39m[49m | ||
[48;2;43;43;43m[38;2;76;86;106m@@ -0,0 +1,3 @@ [39m[49m | ||
[48;2;46;52;64m[38;2;229;233;240m [39m[49m[48;2;48;58;53m[38;2;163;190;140m 1 [39m[49m[48;2;48;58;53m[38;2;163;190;140m + # exclude lock files from git diff [39m[49m | ||
[48;2;46;52;64m[38;2;229;233;240m [39m[49m[48;2;48;58;53m[38;2;163;190;140m 2 [39m[49m[48;2;48;58;53m[38;2;163;190;140m + package-lock.json -diff [39m[49m | ||
[48;2;46;52;64m[38;2;229;233;240m [39m[49m[48;2;48;58;53m[38;2;163;190;140m 3 [39m[49m[48;2;48;58;53m[38;2;163;190;140m + yarn.lock -diff [39m[49m | ||
[48;2;46;52;64m[38;2;229;233;240m [39m[49m[48;2;43;43;43m[38;2;76;86;106m 4 [39m[49m[48;2;43;43;43m[38;2;229;233;240m [39m[49m | ||
`; | ||
const { stdout, stderr } = spawnSync( | ||
'node', | ||
['./build/index.mjs', '--color'], | ||
{ input, encoding: 'utf-8' } | ||
); | ||
console.log({ stdout, stderr }); | ||
if (fs.existsSync(snapshotPath)) { | ||
const expected = fs.readFileSync(snapshotPath, 'utf-8'); | ||
assert.equal(stdout, expected); | ||
} else { | ||
fs.writeFileSync(snapshotPath, stdout); | ||
console.log(`Wrote snapshot to ${snapshotPath}`); | ||
} | ||
assert.equal(stdout, expected); | ||
} | ||
|
||
main(); |