@reporters/testwatch 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.2.0](https://github.com/MoLow/reporters/compare/testwatch-v1.1.1...testwatch-v1.2.0) (2023-06-19)
4
+
5
+
6
+ ### Features
7
+
8
+ * add test:watch script ([4357fbd](https://github.com/MoLow/reporters/commit/4357fbde5f337cfd39226497f8ce0f6760f8a62c))
9
+ * change default file filter ([5968235](https://github.com/MoLow/reporters/commit/596823529cd9a86e5eeada0523825fa215e49efe))
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * don't exit when no tests on initial run ([66bcc2b](https://github.com/MoLow/reporters/commit/66bcc2bc6436b544900cfbceb4bbfb0d93973490))
15
+
3
16
  ## [1.1.1](https://github.com/MoLow/reporters/compare/testwatch-v1.1.0...testwatch-v1.1.1) (2023-06-12)
4
17
 
5
18
 
package/index.js CHANGED
@@ -39,7 +39,7 @@ process.stdin.setRawMode?.(true);
39
39
  class REPL {
40
40
  #controller = new AbortController();
41
41
 
42
- #filesFilter = '';
42
+ #filesFilter = process.argv[2] || '';
43
43
 
44
44
  #testsFilter = '';
45
45
 
@@ -59,7 +59,7 @@ class REPL {
59
59
  async #runTests() {
60
60
  this.#controller.abort();
61
61
  this.#controller = new AbortController();
62
- const filter = this.#filesFilter ? `**/${this.#filesFilter}*.*` : '**/*.test.js';
62
+ const filter = this.#filesFilter ? `**/${this.#filesFilter}*.*` : '**/?(*.)+(spec|test).[jt]s';
63
63
  const files = await glob(filter, { ignore: 'node_modules/**' });
64
64
 
65
65
  if (!files.length) {
@@ -220,8 +220,7 @@ ${Object.entries(this.#currentCommands)
220
220
  }
221
221
 
222
222
  async run() {
223
- await this.#runTests();
224
- await once(this.#emitter, 'drained');
223
+ await Promise.all([once(this.#emitter, 'drained'), this.#runTests()]);
225
224
  this.#emitter.on('drained', () => this.#compactHelp());
226
225
  this.#help();
227
226
  for await (const data of on(process.stdin, 'data')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reporters/testwatch",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "An interactive repl for `node:test`",
5
5
  "keywords": [
6
6
  "node:test",
@@ -10,7 +10,8 @@
10
10
  ],
11
11
  "bin": "./index.js",
12
12
  "scripts": {
13
- "test": "node --test-reporter=spec --test-reporter-destination=stdout --test-reporter=../github/index.js --test-reporter-destination=stdout --test tests/index.test.js"
13
+ "test": "node --test-reporter=spec --test-reporter-destination=stdout --test-reporter=../github/index.js --test-reporter-destination=stdout --test tests/index.test.js",
14
+ "test:watch": "testwatch tests/index"
14
15
  },
15
16
  "bugs": {
16
17
  "url": "https://github.com/MoLow/reporters/issues"
@@ -0,0 +1,6 @@
1
+ const { test } = require('node:test');
2
+ const assert = require('node:assert');
3
+
4
+ test('should not run', () => {
5
+ assert.strictEqual(1 + 2, 3);
6
+ });
@@ -35,11 +35,11 @@ Filter Test
35
35
  pattern › `;
36
36
  const filterFilesPrompt = filterTestsPrompt.replace('test', 'file').replace('Test', 'File');
37
37
 
38
- async function spawnInteractive(commandSequence = 'q') {
38
+ async function spawnInteractive(commandSequence = 'q', args = []) {
39
39
  let stderr = '';
40
40
  let stdout = '';
41
- const child = spawn(process.execPath, ['../../index.js'], {
42
- env: { }, cwd: path.resolve(__dirname, 'fixtures'),
41
+ const child = spawn(process.execPath, ['../../index.js', ...args], {
42
+ env: {}, cwd: path.resolve(__dirname, 'fixtures'),
43
43
  });
44
44
  child.stdin.setEncoding('utf8');
45
45
  let writing = false;
@@ -62,7 +62,7 @@ async function spawnInteractive(commandSequence = 'q') {
62
62
  child.stdout.setEncoding('utf8');
63
63
  child.stdout.on('data', (data) => {
64
64
  stdout += data;
65
- if (stdout.includes(mainMenu)) {
65
+ if (stdout.includes(mainMenu) || stdout.includes(mainMenuWithFilters)) {
66
66
  writeInput();
67
67
  }
68
68
  });
@@ -103,7 +103,7 @@ describe('testwatch', { concurrency: true, skip: !isSupported ? 'unsupported nod
103
103
  });
104
104
  it('should exit on sigkill', async () => {
105
105
  const child = spawn(process.execPath, ['../../index.js'], {
106
- env: { }, cwd: path.resolve(__dirname, 'fixtures'),
106
+ env: {}, cwd: path.resolve(__dirname, 'fixtures'),
107
107
  });
108
108
  let stderr = '';
109
109
  let stdout = '';
@@ -156,6 +156,27 @@ describe('testwatch', { concurrency: true, skip: !isSupported ? 'unsupported nod
156
156
  });
157
157
 
158
158
  describe('files filter', () => {
159
+ it('should not exit if no test found on first run', async () => {
160
+ const { outputs, stderr } = await spawnInteractive('q', ['notexist']);
161
+ const activeFilters = '\nActive Filters: file name **/notexist*.*\n';
162
+ const notFound = '\nNo files found for pattern **/notexist*.*';
163
+ assert.strictEqual(stderr, '');
164
+ assert.deepStrictEqual(outputs, [
165
+ '',
166
+ `${notFound}\n${activeFilters}${mainMenuWithFilters}\n`,
167
+ ]);
168
+ });
169
+
170
+ it('should set first argument as file filter', async () => {
171
+ const { outputs, stderr } = await spawnInteractive('q', ['ind']);
172
+ const activeFilters = '\nActive Filters: file name **/ind*.*\n';
173
+ assert.strictEqual(stderr, '');
174
+ assert.deepStrictEqual(outputs, [
175
+ '',
176
+ `${testsRun[1]}\n${activeFilters}${mainMenuWithFilters}\n`,
177
+ ]);
178
+ });
179
+
159
180
  it('should filter files on "p"', async () => {
160
181
  const { outputs, stderr } = await spawnInteractive(['p', 'index', '\r', 'w', 'q'].join(''));
161
182
  const activeFilters = '\nActive Filters: file name **/index*.*\n';
File without changes