|
| 1 | +/** |
| 2 | + * Copyright (C) Daniel Kuschny (Danielku15) and contributors. |
| 3 | + * Copyright (C) Microsoft Corporation. All rights reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style |
| 6 | + * license that can be found in the LICENSE file or at |
| 7 | + * https://opensource.org/licenses/MIT. |
| 8 | + */ |
| 9 | + |
| 10 | +import { expect } from 'chai'; |
| 11 | +import * as vscode from 'vscode'; |
| 12 | +import { captureTestRun, expectTestTree, getController } from '../util'; |
| 13 | + |
| 14 | +describe('with-hooks', () => { |
| 15 | + it('discovers tests', async () => { |
| 16 | + const c = await getController(); |
| 17 | + |
| 18 | + expectTestTree(c, [ |
| 19 | + [ |
| 20 | + 'hello.test.js', |
| 21 | + [ |
| 22 | + ['with beforeAll hook', [['addition'], ['failing'], ['subtraction']]], |
| 23 | + ['with beforeEach hook', [['addition'], ['failing'], ['subtraction']]], |
| 24 | + [ |
| 25 | + 'with broken after hook (suite must be failed)', |
| 26 | + [['addition'], ['failing'], ['subtraction']], |
| 27 | + ], |
| 28 | + [ |
| 29 | + 'with broken afterEach hook (suite must be failed)', |
| 30 | + [['addition (success)'], ['failing (skipped)'], ['subtraction (skipped)']], |
| 31 | + ], |
| 32 | + [ |
| 33 | + 'with broken before hook (suite must be failed)', |
| 34 | + [['addition (skipped)'], ['failing (skipped)'], ['subtraction (skipped)']], |
| 35 | + ], |
| 36 | + [ |
| 37 | + 'with broken beforeEach hook (suite must be failed)', |
| 38 | + [['addition (skipped)'], ['failing (skipped)'], ['subtraction (skipped)']], |
| 39 | + ], |
| 40 | + ], |
| 41 | + ], |
| 42 | + ]); |
| 43 | + }); |
| 44 | + |
| 45 | + it('runs tests', async () => { |
| 46 | + const c = await getController(); |
| 47 | + const profiles = c.profiles; |
| 48 | + expect(profiles).to.have.lengthOf(2); |
| 49 | + |
| 50 | + const run = await captureTestRun( |
| 51 | + c, |
| 52 | + new vscode.TestRunRequest( |
| 53 | + undefined, |
| 54 | + undefined, |
| 55 | + profiles.find((p) => p.kind === vscode.TestRunProfileKind.Run), |
| 56 | + ), |
| 57 | + ); |
| 58 | + |
| 59 | + run.expectStates({ |
| 60 | + 'hello.test.js/with beforeAll hook/addition': ['enqueued', 'started', 'passed'], |
| 61 | + 'hello.test.js/with beforeAll hook/subtraction': ['enqueued', 'started', 'passed'], |
| 62 | + 'hello.test.js/with beforeAll hook/failing': ['enqueued', 'started', 'failed'], |
| 63 | + 'hello.test.js/with beforeEach hook/addition': ['enqueued', 'started', 'passed'], |
| 64 | + 'hello.test.js/with beforeEach hook/subtraction': ['enqueued', 'started', 'passed'], |
| 65 | + 'hello.test.js/with beforeEach hook/failing': ['enqueued', 'started', 'failed'], |
| 66 | + 'hello.test.js/with broken before hook (suite must be failed)/addition (skipped)': [ |
| 67 | + 'enqueued', |
| 68 | + 'skipped', |
| 69 | + ], |
| 70 | + 'hello.test.js/with broken before hook (suite must be failed)/subtraction (skipped)': [ |
| 71 | + 'enqueued', |
| 72 | + 'skipped', |
| 73 | + ], |
| 74 | + 'hello.test.js/with broken before hook (suite must be failed)/failing (skipped)': [ |
| 75 | + 'enqueued', |
| 76 | + 'skipped', |
| 77 | + ], |
| 78 | + 'hello.test.js/with broken beforeEach hook (suite must be failed)/addition (skipped)': [ |
| 79 | + 'enqueued', |
| 80 | + 'started', |
| 81 | + 'skipped', |
| 82 | + ], |
| 83 | + 'hello.test.js/with broken beforeEach hook (suite must be failed)/subtraction (skipped)': [ |
| 84 | + 'enqueued', |
| 85 | + 'skipped', |
| 86 | + ], |
| 87 | + 'hello.test.js/with broken beforeEach hook (suite must be failed)/failing (skipped)': [ |
| 88 | + 'enqueued', |
| 89 | + 'skipped', |
| 90 | + ], |
| 91 | + 'hello.test.js/with broken after hook (suite must be failed)/addition': [ |
| 92 | + 'enqueued', |
| 93 | + 'started', |
| 94 | + 'passed', |
| 95 | + ], |
| 96 | + 'hello.test.js/with broken after hook (suite must be failed)/subtraction': [ |
| 97 | + 'enqueued', |
| 98 | + 'started', |
| 99 | + 'passed', |
| 100 | + ], |
| 101 | + 'hello.test.js/with broken after hook (suite must be failed)/failing': [ |
| 102 | + 'enqueued', |
| 103 | + 'started', |
| 104 | + 'failed', |
| 105 | + ], |
| 106 | + 'hello.test.js/with broken afterEach hook (suite must be failed)/addition (success)': [ |
| 107 | + 'enqueued', |
| 108 | + 'started', |
| 109 | + 'passed', |
| 110 | + ], |
| 111 | + 'hello.test.js/with broken afterEach hook (suite must be failed)/subtraction (skipped)': [ |
| 112 | + 'enqueued', |
| 113 | + 'skipped', |
| 114 | + ], |
| 115 | + 'hello.test.js/with broken afterEach hook (suite must be failed)/failing (skipped)': [ |
| 116 | + 'enqueued', |
| 117 | + 'skipped', |
| 118 | + ], |
| 119 | + 'hello.test.js/with broken before hook (suite must be failed)': ['failed'], |
| 120 | + 'hello.test.js/with broken beforeEach hook (suite must be failed)': ['failed'], |
| 121 | + 'hello.test.js/with broken after hook (suite must be failed)': ['failed'], |
| 122 | + 'hello.test.js/with broken afterEach hook (suite must be failed)': ['failed'], |
| 123 | + }); |
| 124 | + }); |
| 125 | +}); |
0 commit comments