-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set test state failed if error is thrown in
before
hook (#160)
--------- Co-authored-by: Danielku15 <[email protected]>
- Loading branch information
1 parent
f491294
commit 873dd26
Showing
9 changed files
with
259 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/** | ||
* Copyright (C) Daniel Kuschny (Danielku15) and contributors. | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import * as vscode from 'vscode'; | ||
import { captureTestRun, expectTestTree, getController } from '../util'; | ||
|
||
describe('with-hooks', () => { | ||
it('discovers tests', async () => { | ||
const c = await getController(); | ||
|
||
expectTestTree(c, [ | ||
[ | ||
'hello.test.js', | ||
[ | ||
['with beforeAll hook', [['addition'], ['failing'], ['subtraction']]], | ||
['with beforeEach hook', [['addition'], ['failing'], ['subtraction']]], | ||
[ | ||
'with broken after hook (suite must be failed)', | ||
[['addition'], ['failing'], ['subtraction']], | ||
], | ||
[ | ||
'with broken afterEach hook (suite must be failed)', | ||
[['addition (success)'], ['failing (skipped)'], ['subtraction (skipped)']], | ||
], | ||
[ | ||
'with broken before hook (suite must be failed)', | ||
[['addition (skipped)'], ['failing (skipped)'], ['subtraction (skipped)']], | ||
], | ||
[ | ||
'with broken beforeEach hook (suite must be failed)', | ||
[['addition (skipped)'], ['failing (skipped)'], ['subtraction (skipped)']], | ||
], | ||
], | ||
], | ||
]); | ||
}); | ||
|
||
it('runs tests', async () => { | ||
const c = await getController(); | ||
const profiles = c.profiles; | ||
expect(profiles).to.have.lengthOf(2); | ||
|
||
const run = await captureTestRun( | ||
c, | ||
new vscode.TestRunRequest( | ||
undefined, | ||
undefined, | ||
profiles.find((p) => p.kind === vscode.TestRunProfileKind.Run), | ||
), | ||
); | ||
|
||
run.expectStates({ | ||
'hello.test.js/with beforeAll hook/addition': ['enqueued', 'started', 'passed'], | ||
'hello.test.js/with beforeAll hook/subtraction': ['enqueued', 'started', 'passed'], | ||
'hello.test.js/with beforeAll hook/failing': ['enqueued', 'started', 'failed'], | ||
'hello.test.js/with beforeEach hook/addition': ['enqueued', 'started', 'passed'], | ||
'hello.test.js/with beforeEach hook/subtraction': ['enqueued', 'started', 'passed'], | ||
'hello.test.js/with beforeEach hook/failing': ['enqueued', 'started', 'failed'], | ||
'hello.test.js/with broken before hook (suite must be failed)/addition (skipped)': [ | ||
'enqueued', | ||
'skipped', | ||
], | ||
'hello.test.js/with broken before hook (suite must be failed)/subtraction (skipped)': [ | ||
'enqueued', | ||
'skipped', | ||
], | ||
'hello.test.js/with broken before hook (suite must be failed)/failing (skipped)': [ | ||
'enqueued', | ||
'skipped', | ||
], | ||
'hello.test.js/with broken beforeEach hook (suite must be failed)/addition (skipped)': [ | ||
'enqueued', | ||
'started', | ||
'skipped', | ||
], | ||
'hello.test.js/with broken beforeEach hook (suite must be failed)/subtraction (skipped)': [ | ||
'enqueued', | ||
'skipped', | ||
], | ||
'hello.test.js/with broken beforeEach hook (suite must be failed)/failing (skipped)': [ | ||
'enqueued', | ||
'skipped', | ||
], | ||
'hello.test.js/with broken after hook (suite must be failed)/addition': [ | ||
'enqueued', | ||
'started', | ||
'passed', | ||
], | ||
'hello.test.js/with broken after hook (suite must be failed)/subtraction': [ | ||
'enqueued', | ||
'started', | ||
'passed', | ||
], | ||
'hello.test.js/with broken after hook (suite must be failed)/failing': [ | ||
'enqueued', | ||
'started', | ||
'failed', | ||
], | ||
'hello.test.js/with broken afterEach hook (suite must be failed)/addition (success)': [ | ||
'enqueued', | ||
'started', | ||
'passed', | ||
], | ||
'hello.test.js/with broken afterEach hook (suite must be failed)/subtraction (skipped)': [ | ||
'enqueued', | ||
'skipped', | ||
], | ||
'hello.test.js/with broken afterEach hook (suite must be failed)/failing (skipped)': [ | ||
'enqueued', | ||
'skipped', | ||
], | ||
'hello.test.js/with broken before hook (suite must be failed)': ['failed'], | ||
'hello.test.js/with broken beforeEach hook (suite must be failed)': ['failed'], | ||
'hello.test.js/with broken after hook (suite must be failed)': ['failed'], | ||
'hello.test.js/with broken afterEach hook (suite must be failed)': ['failed'], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
spec: '**/*.test.js' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
const { strictEqual } = require('node:assert'); | ||
|
||
describe('with beforeAll hook', () => { | ||
before(() => { | ||
console.log('Before hook executed once!'); | ||
}); | ||
|
||
it('addition', async () => { | ||
strictEqual(1 + 1, 2); | ||
}); | ||
|
||
it('subtraction', async () => { | ||
strictEqual(1 - 1, 0); | ||
}); | ||
it('failing', async () => { | ||
strictEqual(1 * 1, 0); | ||
}); | ||
}); | ||
|
||
describe('with beforeEach hook', () => { | ||
beforeEach(() => { | ||
console.log('BeforeEach hook executed every time!'); | ||
}); | ||
|
||
it('addition', async () => { | ||
strictEqual(1 + 1, 2); | ||
}); | ||
|
||
it('subtraction', async () => { | ||
strictEqual(1 - 1, 0); | ||
}); | ||
it('failing', async () => { | ||
strictEqual(1 * 1, 0); | ||
}); | ||
}); | ||
|
||
describe('with broken before hook (suite must be failed)', () => { | ||
before(() => { | ||
throw new Error('Before hook is broken!!!'); | ||
}); | ||
|
||
it('addition (skipped)', async () => { | ||
strictEqual(1 + 1, 2); | ||
}); | ||
|
||
it('subtraction (skipped)', async () => { | ||
strictEqual(1 - 1, 0); | ||
}); | ||
it('failing (skipped)', async () => { | ||
strictEqual(1 * 1, 0); | ||
}); | ||
}); | ||
|
||
describe('with broken beforeEach hook (suite must be failed)', () => { | ||
beforeEach(() => { | ||
throw new Error('BeforeEach hook is broken!!!'); | ||
}); | ||
|
||
it('addition (skipped)', async () => { | ||
strictEqual(1 + 1, 2); | ||
}); | ||
|
||
it('subtraction (skipped)', async () => { | ||
strictEqual(1 - 1, 0); | ||
}); | ||
it('failing (skipped)', async () => { | ||
strictEqual(1 * 1, 0); | ||
}); | ||
}); | ||
|
||
describe('with broken after hook (suite must be failed)', () => { | ||
after(() => { | ||
throw new Error('After hook is broken!!!'); | ||
}); | ||
|
||
it('addition', async () => { | ||
strictEqual(1 + 1, 2); | ||
}); | ||
|
||
it('subtraction', async () => { | ||
strictEqual(1 - 1, 0); | ||
}); | ||
it('failing', async () => { | ||
strictEqual(1 * 1, 0); | ||
}); | ||
}); | ||
|
||
describe('with broken afterEach hook (suite must be failed)', () => { | ||
afterEach(() => { | ||
throw new Error('After each hook is broken!!!'); | ||
}); | ||
|
||
it('addition (success)', async () => { | ||
strictEqual(1 + 1, 2); | ||
}); | ||
|
||
it('subtraction (skipped)', async () => { | ||
strictEqual(1 - 1, 0); | ||
}); | ||
it('failing (skipped)', async () => { | ||
strictEqual(1 * 1, 0); | ||
}); | ||
}); |