| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -770,6 +770,9 @@ run({ files: [path.resolve('./tests/test.js')] }) | |||
| 770 | 770 | <!-- YAML | |
| 771 | 771 | added: v18.0.0 | |
| 772 | 772 | changes: | |
| 773 | + - version: REPLACEME | ||
| 774 | + pr-url: https://github.com/nodejs/node/pull/47909 | ||
| 775 | + description: Added the `skip`, `todo`, and `only` shorthands. | ||
| 773 | 776 | - version: v18.8.0 | |
| 774 | 777 | pr-url: https://github.com/nodejs/node/pull/43554 | |
| 775 | 778 | description: Add a `signal` option. | |
@@ -841,6 +844,21 @@ The `timeout` option can be used to fail the test if it takes longer than | |||
| 841 | 844 | canceling tests because a running test might block the application thread and | |
| 842 | 845 | thus prevent the scheduled cancellation. | |
| 843 | 846 | ||
| 847 | + ## `test.skip([name][, options][, fn])` | ||
| 848 | + | ||
| 849 | + Shorthand for skipping a test, | ||
| 850 | + same as [`test([name], { skip: true }[, fn])`][it options]. | ||
| 851 | + | ||
| 852 | + ## `test.todo([name][, options][, fn])` | ||
| 853 | + | ||
| 854 | + Shorthand for marking a test as `TODO`, | ||
| 855 | + same as [`test([name], { todo: true }[, fn])`][it options]. | ||
| 856 | + | ||
| 857 | + ## `test.only([name][, options][, fn])` | ||
| 858 | + | ||
| 859 | + Shorthand for marking a test as `only`, | ||
| 860 | + same as [`test([name], { only: true }[, fn])`][it options]. | ||
| 861 | + | ||
| 844 | 862 | ## `describe([name][, options][, fn])` | |
| 845 | 863 | ||
| 846 | 864 | * `name` {string} The name of the suite, which is displayed when reporting test | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,7 +201,7 @@ async function startSubtest(subtest) { | |||
| 201 | 201 | await subtest.start(); | |
| 202 | 202 | } | |
| 203 | 203 | ||
| 204 | - function runInParentContext(Factory, addShorthands = true) { | ||
| 204 | + function runInParentContext(Factory) { | ||
| 205 | 205 | function run(name, options, fn, overrides) { | |
| 206 | 206 | const parent = testResources.get(executionAsyncId()) || getGlobalRoot(); | |
| 207 | 207 | const subtest = parent.createSubtest(Factory, name, options, fn, overrides); | |
@@ -212,10 +212,6 @@ function runInParentContext(Factory, addShorthands = true) { | |||
| 212 | 212 | } | |
| 213 | 213 | ||
| 214 | 214 | const test = (name, options, fn) => run(name, options, fn); | |
| 215 | - if (!addShorthands) { | ||
| 216 | - return test; | ||
| 217 | - } | ||
| 218 | - | ||
| 219 | 215 | ArrayPrototypeForEach(['skip', 'todo', 'only'], (keyword) => { | |
| 220 | 216 | test[keyword] = (name, options, fn) => { | |
| 221 | 217 | run(name, options, fn, { [keyword]: true }); | |
@@ -233,7 +229,7 @@ function hook(hook) { | |||
| 233 | 229 | ||
| 234 | 230 | module.exports = { | |
| 235 | 231 | createTestTree, | |
| 236 | - test: runInParentContext(Test, false), | ||
| 232 | + test: runInParentContext(Test), | ||
| 237 | 233 | describe: runInParentContext(Suite), | |
| 238 | 234 | it: runInParentContext(Test), | |
| 239 | 235 | 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