| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -803,6 +803,15 @@ Shorthand for skipping a suite, same as [`describe([name], { skip: true }[, fn]) | |||
| 803 | 803 | Shorthand for marking a suite as `TODO`, same as | |
| 804 | 804 | [`describe([name], { todo: true }[, fn])`][describe options]. | |
| 805 | 805 | ||
| 806 | + ## `describe.only([name][, options][, fn])` | ||
| 807 | + | ||
| 808 | + <!-- YAML | ||
| 809 | + added: REPLACEME | ||
| 810 | + --> | ||
| 811 | + | ||
| 812 | + Shorthand for marking a suite as `only`, same as | ||
| 813 | + [`describe([name], { only: true }[, fn])`][describe options]. | ||
| 814 | + | ||
| 806 | 815 | ## `it([name][, options][, fn])` | |
| 807 | 816 | ||
| 808 | 817 | * `name` {string} The name of the test, which is displayed when reporting test | |
@@ -827,6 +836,15 @@ same as [`it([name], { skip: true }[, fn])`][it options]. | |||
| 827 | 836 | Shorthand for marking a test as `TODO`, | |
| 828 | 837 | same as [`it([name], { todo: true }[, fn])`][it options]. | |
| 829 | 838 | ||
| 839 | + ## `it.only([name][, options][, fn])` | ||
| 840 | + | ||
| 841 | + <!-- YAML | ||
| 842 | + added: REPLACEME | ||
| 843 | + --> | ||
| 844 | + | ||
| 845 | + Shorthand for marking a test as `only`, | ||
| 846 | + same as [`it([name], { only: true }[, fn])`][it options]. | ||
| 847 | + | ||
| 830 | 848 | ## `before([fn][, options])` | |
| 831 | 849 | ||
| 832 | 850 | <!-- YAML | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -195,7 +195,7 @@ function runInParentContext(Factory) { | |||
| 195 | 195 | run(name, options, fn); | |
| 196 | 196 | }; | |
| 197 | 197 | ||
| 198 | - ArrayPrototypeForEach(['skip', 'todo'], (keyword) => { | ||
| 198 | + ArrayPrototypeForEach(['skip', 'todo', 'only'], (keyword) => { | ||
| 199 | 199 | cb[keyword] = (name, options, fn) => { | |
| 200 | 200 | run(name, options, fn, { [keyword]: true }); | |
| 201 | 201 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | // Flags: --no-warnings --test-only | |
| 2 | 2 | 'use strict'; | |
| 3 | 3 | require('../common'); | |
| 4 | - const test = require('node:test'); | ||
| 4 | + const { test, describe, it } = require('node:test'); | ||
| 5 | 5 | ||
| 6 | 6 | // These tests should be skipped based on the 'only' option. | |
| 7 | 7 | test('only = undefined'); | |
@@ -46,3 +46,37 @@ test('only = true, with subtests', { only: true }, async (t) => { | |||
| 46 | 46 | await t.test('skipped subtest 3', { only: false }); | |
| 47 | 47 | await t.test('skipped subtest 4', { skip: true }); | |
| 48 | 48 | }); | |
| 49 | + | ||
| 50 | + describe.only('describe only = true, with subtests', () => { | ||
| 51 | + it('`it` subtest 1 should run', () => {}); | ||
| 52 | + | ||
| 53 | + it('`it` subtest 2 should run', async () => {}); | ||
| 54 | + }); | ||
| 55 | + | ||
| 56 | + describe.only('describe only = true, with a mixture of subtests', () => { | ||
| 57 | + it.only('`it` subtest 1', () => {}); | ||
| 58 | + | ||
| 59 | + it.only('`it` async subtest 1', async () => {}); | ||
| 60 | + | ||
| 61 | + it('`it` subtest 2 only=true', { only: true }); | ||
| 62 | + | ||
| 63 | + it('`it` subtest 2 only=false', { only: false }, () => { | ||
| 64 | + throw new Error('This should not run'); | ||
| 65 | + }); | ||
| 66 | + | ||
| 67 | + it.skip('`it` subtest 3 skip', () => { | ||
| 68 | + throw new Error('This should not run'); | ||
| 69 | + }); | ||
| 70 | + | ||
| 71 | + it.todo('`it` subtest 4 todo', { only: false }, () => { | ||
| 72 | + throw new Error('This should not run'); | ||
| 73 | + }); | ||
| 74 | + }); | ||
| 75 | + | ||
| 76 | + describe.only('describe only = true, with subtests', () => { | ||
| 77 | + test('subtest should run', () => {}); | ||
| 78 | + | ||
| 79 | + test('async subtest should run', async () => {}); | ||
| 80 | + | ||
| 81 | + test('subtest should be skipped', { only: false }, () => {}); | ||
| 82 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,9 +116,82 @@ ok 11 - only = true, with subtests | |||
| 116 | 116 | --- | |
| 117 | 117 | duration_ms: * | |
| 118 | 118 | ... | |
| 119 | - 1..11 | ||
| 120 | - # tests 11 | ||
| 121 | - # pass 1 | ||
| 119 | + # Subtest: describe only = true, with subtests | ||
| 120 | + # Subtest: `it` subtest 1 should run | ||
| 121 | + ok 1 - `it` subtest 1 should run | ||
| 122 | + --- | ||
| 123 | + duration_ms: * | ||
| 124 | + ... | ||
| 125 | + # Subtest: `it` subtest 2 should run | ||
| 126 | + ok 2 - `it` subtest 2 should run | ||
| 127 | + --- | ||
| 128 | + duration_ms: * | ||
| 129 | + ... | ||
| 130 | + 1..2 | ||
| 131 | + ok 12 - describe only = true, with subtests | ||
| 132 | + --- | ||
| 133 | + duration_ms: * | ||
| 134 | + ... | ||
| 135 | + # Subtest: describe only = true, with a mixture of subtests | ||
| 136 | + # Subtest: `it` subtest 1 | ||
| 137 | + ok 1 - `it` subtest 1 | ||
| 138 | + --- | ||
| 139 | + duration_ms: * | ||
| 140 | + ... | ||
| 141 | + # Subtest: `it` async subtest 1 | ||
| 142 | + ok 2 - `it` async subtest 1 | ||
| 143 | + --- | ||
| 144 | + duration_ms: * | ||
| 145 | + ... | ||
| 146 | + # Subtest: `it` subtest 2 only=true | ||
| 147 | + ok 3 - `it` subtest 2 only=true | ||
| 148 | + --- | ||
| 149 | + duration_ms: * | ||
| 150 | + ... | ||
| 151 | + # Subtest: `it` subtest 2 only=false | ||
| 152 | + ok 4 - `it` subtest 2 only=false # SKIP 'only' option not set | ||
| 153 | + --- | ||
| 154 | + duration_ms: * | ||
| 155 | + ... | ||
| 156 | + # Subtest: `it` subtest 3 skip | ||
| 157 | + ok 5 - `it` subtest 3 skip # SKIP | ||
| 158 | + --- | ||
| 159 | + duration_ms: * | ||
| 160 | + ... | ||
| 161 | + # Subtest: `it` subtest 4 todo | ||
| 162 | + ok 6 - `it` subtest 4 todo # SKIP 'only' option not set | ||
| 163 | + --- | ||
| 164 | + duration_ms: * | ||
| 165 | + ... | ||
| 166 | + 1..6 | ||
| 167 | + ok 13 - describe only = true, with a mixture of subtests | ||
| 168 | + --- | ||
| 169 | + duration_ms: * | ||
| 170 | + ... | ||
| 171 | + # Subtest: describe only = true, with subtests | ||
| 172 | + # Subtest: subtest should run | ||
| 173 | + ok 1 - subtest should run | ||
| 174 | + --- | ||
| 175 | + duration_ms: * | ||
| 176 | + ... | ||
| 177 | + # Subtest: async subtest should run | ||
| 178 | + ok 2 - async subtest should run | ||
| 179 | + --- | ||
| 180 | + duration_ms: * | ||
| 181 | + ... | ||
| 182 | + # Subtest: subtest should be skipped | ||
| 183 | + ok 3 - subtest should be skipped # SKIP 'only' option not set | ||
| 184 | + --- | ||
| 185 | + duration_ms: * | ||
| 186 | + ... | ||
| 187 | + 1..3 | ||
| 188 | + ok 14 - describe only = true, with subtests | ||
| 189 | + --- | ||
| 190 | + duration_ms: * | ||
| 191 | + ... | ||
| 192 | + 1..14 | ||
| 193 | + # tests 14 | ||
| 194 | + # pass 4 | ||
| 122 | 195 | # fail 0 | |
| 123 | 196 | # cancelled 0 | |
| 124 | 197 | # skipped 10 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments