Skip to content

Commit

Permalink
test: Add actual test execution of hooks tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielku15 committed Oct 20, 2024
1 parent baf3519 commit 79065e4
Showing 1 changed file with 125 additions and 0 deletions.
125 changes: 125 additions & 0 deletions src/test/integration/with-hooks.test.ts
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'],
});
});
});

0 comments on commit 79065e4

Please sign in to comment.