Skip to content

Commit

Permalink
feat: change default file filter
Browse files Browse the repository at this point in the history
  • Loading branch information
mikicho authored and MoLow committed Jun 16, 2023
1 parent c728863 commit 5968235
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/testwatch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ process.stdin.setRawMode?.(true);
class REPL {
#controller = new AbortController();

#filesFilter = '';
#filesFilter = process.argv[2] || '';

#testsFilter = '';

Expand All @@ -59,7 +59,7 @@ class REPL {
async #runTests() {
this.#controller.abort();
this.#controller = new AbortController();
const filter = this.#filesFilter ? `**/${this.#filesFilter}*.*` : '**/*.test.js';
const filter = this.#filesFilter ? `**/${this.#filesFilter}*.*` : '**/?(*.)+(spec|test).[jt]s';
const files = await glob(filter, { ignore: 'node_modules/**' });

if (!files.length) {
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions packages/testwatch/tests/fixtures/not-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { test } = require('node:test');
const assert = require('node:assert');

test('should not run', () => {
assert.strictEqual(1 + 2, 3);
});
20 changes: 15 additions & 5 deletions packages/testwatch/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ Filter Test
pattern › `;
const filterFilesPrompt = filterTestsPrompt.replace('test', 'file').replace('Test', 'File');

async function spawnInteractive(commandSequence = 'q') {
async function spawnInteractive(commandSequence = 'q', args = []) {
let stderr = '';
let stdout = '';
const child = spawn(process.execPath, ['../../index.js'], {
env: { }, cwd: path.resolve(__dirname, 'fixtures'),
const child = spawn(process.execPath, ['../../index.js', ...args], {
env: {}, cwd: path.resolve(__dirname, 'fixtures'),
});
child.stdin.setEncoding('utf8');
let writing = false;
Expand All @@ -62,7 +62,7 @@ async function spawnInteractive(commandSequence = 'q') {
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => {
stdout += data;
if (stdout.includes(mainMenu)) {
if (stdout.includes(mainMenu) || stdout.includes(mainMenuWithFilters)) {
writeInput();
}
});
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('testwatch', { concurrency: true, skip: !isSupported ? 'unsupported nod
});
it('should exit on sigkill', async () => {
const child = spawn(process.execPath, ['../../index.js'], {
env: { }, cwd: path.resolve(__dirname, 'fixtures'),
env: {}, cwd: path.resolve(__dirname, 'fixtures'),
});
let stderr = '';
let stdout = '';
Expand Down Expand Up @@ -156,6 +156,16 @@ describe('testwatch', { concurrency: true, skip: !isSupported ? 'unsupported nod
});

describe('files filter', () => {
it('should set first argument as file filter', async () => {
const { outputs, stderr } = await spawnInteractive('q', ['ind']);
const activeFilters = '\nActive Filters: file name **/ind*.*\n';
assert.strictEqual(stderr, '');
assert.deepStrictEqual(outputs, [
'',
`${testsRun[1]}\n${activeFilters}${mainMenuWithFilters}\n`,
]);
});

it('should filter files on "p"', async () => {
const { outputs, stderr } = await spawnInteractive(['p', 'index', '\r', 'w', 'q'].join(''));
const activeFilters = '\nActive Filters: file name **/index*.*\n';
Expand Down

0 comments on commit 5968235

Please sign in to comment.