| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -789,6 +789,9 @@ added: | |||
| 789 | 789 | - v18.0.0 | |
| 790 | 790 | - v16.17.0 | |
| 791 | 791 | changes: | |
| 792 | + - version: REPLACEME | ||
| 793 | + pr-url: https://github.com/nodejs/node/pull/47909 | ||
| 794 | + description: Added the `skip`, `todo`, and `only` shorthands. | ||
| 792 | 795 | - version: | |
| 793 | 796 | - v18.8.0 | |
| 794 | 797 | - v16.18.0 | |
@@ -864,6 +867,21 @@ The `timeout` option can be used to fail the test if it takes longer than | |||
| 864 | 867 | canceling tests because a running test might block the application thread and | |
| 865 | 868 | thus prevent the scheduled cancellation. | |
| 866 | 869 | ||
| 870 | + ## `test.skip([name][, options][, fn])` | ||
| 871 | + | ||
| 872 | + Shorthand for skipping a test, | ||
| 873 | + same as [`test([name], { skip: true }[, fn])`][it options]. | ||
| 874 | + | ||
| 875 | + ## `test.todo([name][, options][, fn])` | ||
| 876 | + | ||
| 877 | + Shorthand for marking a test as `TODO`, | ||
| 878 | + same as [`test([name], { todo: true }[, fn])`][it options]. | ||
| 879 | + | ||
| 880 | + ## `test.only([name][, options][, fn])` | ||
| 881 | + | ||
| 882 | + Shorthand for marking a test as `only`, | ||
| 883 | + same as [`test([name], { only: true }[, fn])`][it options]. | ||
| 884 | + | ||
| 867 | 885 | ## `describe([name][, options][, fn])` | |
| 868 | 886 | ||
| 869 | 887 | * `name` {string} The name of the suite, which is displayed when reporting test | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -203,7 +203,7 @@ async function startSubtest(subtest) { | |||
| 203 | 203 | await subtest.start(); | |
| 204 | 204 | } | |
| 205 | 205 | ||
| 206 | - function runInParentContext(Factory, addShorthands = true) { | ||
| 206 | + function runInParentContext(Factory) { | ||
| 207 | 207 | function run(name, options, fn, overrides) { | |
| 208 | 208 | const parent = testResources.get(executionAsyncId()) || getGlobalRoot(); | |
| 209 | 209 | const subtest = parent.createSubtest(Factory, name, options, fn, overrides); | |
@@ -214,10 +214,6 @@ function runInParentContext(Factory, addShorthands = true) { | |||
| 214 | 214 | } | |
| 215 | 215 | ||
| 216 | 216 | const test = (name, options, fn) => run(name, options, fn); | |
| 217 | - if (!addShorthands) { | ||
| 218 | - return test; | ||
| 219 | - } | ||
| 220 | - | ||
| 221 | 217 | ArrayPrototypeForEach(['skip', 'todo', 'only'], (keyword) => { | |
| 222 | 218 | test[keyword] = (name, options, fn) => { | |
| 223 | 219 | run(name, options, fn, { [keyword]: true }); | |
@@ -235,7 +231,7 @@ function hook(hook) { | |||
| 235 | 231 | ||
| 236 | 232 | module.exports = { | |
| 237 | 233 | createTestTree, | |
| 238 | - test: runInParentContext(Test, false), | ||
| 234 | + test: runInParentContext(Test), | ||
| 239 | 235 | describe: runInParentContext(Suite), | |
| 240 | 236 | it: runInParentContext(Test), | |
| 241 | 237 | before: hook('before'), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,6 +71,24 @@ describe.only('describe only = true, with a mixture of subtests', () => { | |||
| 71 | 71 | it.todo('`it` subtest 4 todo', { only: false }, () => { | |
| 72 | 72 | throw new Error('This should not run'); | |
| 73 | 73 | }); | |
| 74 | + | ||
| 75 | + test.only('`test` subtest 1', () => {}); | ||
| 76 | + | ||
| 77 | + test.only('`test` async subtest 1', async () => {}); | ||
| 78 | + | ||
| 79 | + test('`test` subtest 2 only=true', { only: true }); | ||
| 80 | + | ||
| 81 | + test('`test` subtest 2 only=false', { only: false }, () => { | ||
| 82 | + throw new Error('This should not run'); | ||
| 83 | + }); | ||
| 84 | + | ||
| 85 | + test.skip('`test` subtest 3 skip', () => { | ||
| 86 | + throw new Error('This should not run'); | ||
| 87 | + }); | ||
| 88 | + | ||
| 89 | + test.todo('`test` subtest 4 todo', { only: false }, () => { | ||
| 90 | + throw new Error('This should not run'); | ||
| 91 | + }); | ||
| 74 | 92 | }); | |
| 75 | 93 | ||
| 76 | 94 | describe.only('describe only = true, with subtests', () => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -164,7 +164,37 @@ ok 12 - describe only = true, with subtests | |||
| 164 | 164 | --- | |
| 165 | 165 | duration_ms: * | |
| 166 | 166 | ... | |
| 167 | - 1..6 | ||
| 167 | + # Subtest: `test` subtest 1 | ||
| 168 | + ok 7 - `test` subtest 1 | ||
| 169 | + --- | ||
| 170 | + duration_ms: * | ||
| 171 | + ... | ||
| 172 | + # Subtest: `test` async subtest 1 | ||
| 173 | + ok 8 - `test` async subtest 1 | ||
| 174 | + --- | ||
| 175 | + duration_ms: * | ||
| 176 | + ... | ||
| 177 | + # Subtest: `test` subtest 2 only=true | ||
| 178 | + ok 9 - `test` subtest 2 only=true | ||
| 179 | + --- | ||
| 180 | + duration_ms: * | ||
| 181 | + ... | ||
| 182 | + # Subtest: `test` subtest 2 only=false | ||
| 183 | + ok 10 - `test` subtest 2 only=false # SKIP 'only' option not set | ||
| 184 | + --- | ||
| 185 | + duration_ms: * | ||
| 186 | + ... | ||
| 187 | + # Subtest: `test` subtest 3 skip | ||
| 188 | + ok 11 - `test` subtest 3 skip # SKIP | ||
| 189 | + --- | ||
| 190 | + duration_ms: * | ||
| 191 | + ... | ||
| 192 | + # Subtest: `test` subtest 4 todo | ||
| 193 | + ok 12 - `test` subtest 4 todo # SKIP 'only' option not set | ||
| 194 | + --- | ||
| 195 | + duration_ms: * | ||
| 196 | + ... | ||
| 197 | + 1..12 | ||
| 168 | 198 | ok 13 - describe only = true, with a mixture of subtests | |
| 169 | 199 | --- | |
| 170 | 200 | duration_ms: * | |
@@ -193,11 +223,11 @@ ok 14 - describe only = true, with subtests | |||
| 193 | 223 | type: 'suite' | |
| 194 | 224 | ... | |
| 195 | 225 | 1..14 | |
| 196 | - # tests 34 | ||
| 226 | + # tests 40 | ||
| 197 | 227 | # suites 3 | |
| 198 | - # pass 14 | ||
| 228 | + # pass 17 | ||
| 199 | 229 | # fail 0 | |
| 200 | 230 | # cancelled 0 | |
| 201 | - # skipped 20 | ||
| 231 | + # skipped 23 | ||
| 202 | 232 | # todo 0 | |
| 203 | 233 | # duration_ms * | |
| Back | FazBrowse Home | New Git URL |
0 commit comments