Skip to content

Commit

Permalink
chore: go overboard
Browse files Browse the repository at this point in the history
Make the type system as smart as the function.
  • Loading branch information
lishaduck committed Jul 9, 2024
1 parent 29408ed commit e737ee0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
8 changes: 7 additions & 1 deletion test/flags.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const TestCli = require('./jest-helpers/cli');
const snapshotter = require('./snapshotter');

/**
* @template {string} N
* @param {N} name
* @returns {`test/snapshots/flags/${N}.txt`}
*/
function testName(name) {
return `test/snapshots/flags/${name}.txt`;
return snapshotter.snapshotPath('flags', name);
}

test('Running with an unknown flag', async () => {
Expand Down
8 changes: 7 additions & 1 deletion test/help.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const TestCli = require('./jest-helpers/cli');
const snapshotter = require('./snapshotter');

/**
* @template {string} N
* @param {N} name
* @returns {`test/snapshots/help/${N}.txt`}
*/
function testName(name) {
return `test/snapshots/help/${name}.txt`;
return snapshotter.snapshotPath('help', name);
}

test('--help', async () => {
Expand Down
8 changes: 7 additions & 1 deletion test/review.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
const path = require('node:path');
const TestCli = require('./jest-helpers/cli');
const snapshotter = require('./snapshotter');

/**
* @template {string} N
* @param {N} name
* @returns {`test/snapshots/review/${N}.txt`}
*/
function testName(name) {
return `test/snapshots/review/${name}.txt`;
return snapshotter.snapshotPath('review', name);
}

test('Regular run from inside the project', async () => {
Expand Down
12 changes: 12 additions & 0 deletions test/snapshotter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @template {string} G
* @template {string} N
* @param {G} group
* @param {N} name
* @returns {`test/snapshots/${G}/${N}.txt`}
*/
function snapshotPath(group, name) {
return `test/snapshots/${group}/${name}.txt`;
}

module.exports = {snapshotPath};
8 changes: 7 additions & 1 deletion test/suppress.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const path = require('node:path');
const childProcess = require('node:child_process');
const TestCli = require('./jest-helpers/cli');
const snapshotter = require('./snapshotter');

/**
* @template {string} N
* @param {N} name
* @returns {`test/snapshots/suppress/${N}.txt`}
*/
function testName(name) {
return `test/snapshots/suppress/${name}.txt`;
return snapshotter.snapshotPath('suppress', name);
}

test('Running on project with only suppressed errors remaining should not exit with failure', () => {
Expand Down

0 comments on commit e737ee0

Please sign in to comment.