Skip to content

Commit

Permalink
feat: add factory.runTest to run an inline test
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Sep 23, 2023
1 parent 5a24058 commit 9dce0e9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
29 changes: 27 additions & 2 deletions factories/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ import { GlobalHooks } from '../src/hooks.js'
import { CliParser } from '../src/cli_parser.js'
import { ConfigManager } from '../src/config_manager.js'
import { createTest, createTestGroup } from '../src/create_test.js'
import { Group, Suite, Runner, Emitter } from '../modules/core/main.js'
import type { CLIArgs, Config, NormalizedConfig, RunnerSummary } from '../src/types.js'
import { Group, Suite, Runner, Emitter, TestContext } from '../modules/core/main.js'
import type {
Config,
CLIArgs,
TestExecutor,
RunnerSummary,
NormalizedConfig,
} from '../src/types.js'

/**
* Runner factory exposes the API to run dummy suites, groups and tests.
Expand Down Expand Up @@ -199,6 +205,25 @@ export class RunnerFactory {
return this
}

/**
* Run a test using the runner
*/
async runTest(
title: string,
callback: TestExecutor<TestContext, undefined>
): Promise<RunnerSummary> {
const defaultSuite = new Suite('default', this.#emitter, this.#refiner)
const test = createTest(title, this.#emitter, this.#refiner, {
suite: defaultSuite,
file: this.#file,
}).run(callback)

defaultSuite.add(test)

this.withSuites([defaultSuite])
return this.run()
}

/**
* Run dummy tests. You might use
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/config_manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import chaiSubset from 'chai-subset'
import { Refiner } from '@japa/core'
import { assert, default as chai } from 'chai'

import { ndjson, spec, dot } from '../src/reporters/main.js'
import { CliParser } from '../src/cli_parser.js'
import type { CLIArgs, Config } from '../src/types.js'
import { ConfigManager, NOOP } from '../src/config_manager.js'
import { wrapAssertions } from '../tests_helpers/main.js'
import { ndjson, spec, dot } from '../src/reporters/main.js'
import { ConfigManager, NOOP } from '../src/config_manager.js'

chai.use(chaiSubset)

Expand Down
2 changes: 1 addition & 1 deletion tests/runner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { GlobalHooks } from '../src/hooks.js'
import { ConfigManager } from '../src/config_manager.js'
import { pEvent, wrapAssertions } from '../tests_helpers/main.js'
import { createTest, createTestGroup } from '../src/create_test.js'
import { clearCache, getFailedTests, retryPlugin } from '../src/plugins/retry.js'
import { Emitter, Refiner, Runner, Suite } from '../modules/core/main.js'
import { clearCache, getFailedTests, retryPlugin } from '../src/plugins/retry.js'

test.describe('Runner | create tests and groups', () => {
test('raise error when defining nested groups', async () => {
Expand Down

0 comments on commit 9dce0e9

Please sign in to comment.