@reporters/bail 1.0.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 ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 (2023-06-05)
4
+
5
+
6
+ ### Features
7
+
8
+ * add @reporters/bail package ([9a2ca5c](https://github.com/MoLow/reporters/commit/9a2ca5c98e029e6b73238adfb0f6e68da9011d87))
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ [![npm version](https://img.shields.io/npm/v/@reporters/bail)](https://www.npmjs.com/package/@reporters/bail) ![tests](https://github.com/MoLow/reporters/actions/workflows/test.yaml/badge.svg?branch=main) [![codecov](https://codecov.io/gh/MoLow/reporters/branch/main/graph/badge.svg?token=0LFVC8SCQV)](https://codecov.io/gh/MoLow/reporters)
2
+
3
+ # `node:test` Bail on failure
4
+ A package to bail on the first test failure of a test run
5
+ using node built in test runner.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install --save-dev @reporters/bail
11
+ ```
12
+ or
13
+ ```bash
14
+ yarn add --dev @reporters/bail
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```bash
20
+ node --test \
21
+ --test-reporter=@reporters/bail --test-reporter-destination=stderr \
22
+ --test-reporter=spec --test-reporter-destination=stdout
23
+ ```
24
+
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = async function* bail(source) {
2
+ for await (const event of source) {
3
+ if (event.type === 'test:fail') {
4
+ yield `\n\u001b[31m✖ Bailing on failed test: ${event.data.name}\u001b[0m\n`;
5
+ throw new Error('Bail');
6
+ }
7
+ }
8
+ };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@reporters/bail",
3
+ "version": "1.0.0",
4
+ "description": "A Bail library for `node:test`",
5
+ "keywords": [
6
+ "node:test",
7
+ "test",
8
+ "reporter",
9
+ "reporters"
10
+ ],
11
+ "scripts": {
12
+ "test": "node --test-reporter=spec --test-reporter-destination=stdout --test-reporter=../github/index.js --test-reporter-destination=stdout --test"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/MoLow/reporters/issues"
16
+ },
17
+ "main": "index.js",
18
+ "homepage": "https://github.com/MoLow/reporters/tree/main/packages/bail",
19
+ "repository": "https://github.com/MoLow/reporters.git",
20
+ "author": "Moshe Atlow",
21
+ "license": "MIT"
22
+ }
@@ -0,0 +1,7 @@
1
+ const { describe, test } = require('node:test');
2
+ const assert = require('node:assert');
3
+
4
+ describe('enforce no concurrent tests', { concurrent: false }, () => {
5
+ test('fail', async () => assert.fail());
6
+ test('dont run', async () => {});
7
+ });
@@ -0,0 +1,3 @@
1
+ const { test } = require('node:test');
2
+
3
+ test('pass');
@@ -0,0 +1,24 @@
1
+ const { test } = require('node:test');
2
+ const { spawnSync } = require('child_process');
3
+ const assert = require('assert');
4
+
5
+ test('pass should not interfere with passing test', () => {
6
+ const child = spawnSync(process.execPath, [
7
+ '--test-reporter', 'dot', '--test-reporter-destination', 'stdout',
8
+ '--test-reporter', './index.js', '--test-reporter-destination', 'stdout', 'tests/fixtures/pass.js',
9
+ ], { env: {} });
10
+ assert.strictEqual(child.stderr?.toString(), '');
11
+ assert.strictEqual(child.stdout?.toString(), '.\n');
12
+ assert.strictEqual(child.status, 0);
13
+ });
14
+
15
+ test('fail should stop after failed test', () => {
16
+ const child = spawnSync(process.execPath, [
17
+ '--test-reporter', 'dot', '--test-reporter-destination', 'stdout',
18
+ '--test-reporter', './index.js', '--test-reporter-destination', 'stdout',
19
+ 'tests/fixtures/fail.js', 'tests/fixtures/pass.js',
20
+ ], { env: {} });
21
+ assert.strictEqual(child.stderr?.toString(), '');
22
+ assert.strictEqual(child.stdout?.toString(), 'X\n\x1B[31m✖ Bailing on failed test: fail\x1B[0m\n');
23
+ assert.strictEqual(child.status, 1);
24
+ });