Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ Use `expect(actual_value)` with assertions:

`skip()` Declares a skipped test or test group. Test/s is/are never run.

`only()` Declares an exclusive test or test group that will be executed. If used, all other tests are skipped.

### `Example↓`


Expand All @@ -169,6 +171,16 @@ test.skip('description', () => {})
describe.skip('description', () => {})
```

```js
test.only('description', () => {
// Body of the only test that will be executed
})
//or
describe.only('description', () => {
// Body of the only test group that will be executed
})
```

---

## Context options
Expand Down
12 changes: 12 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ Use `expect(actual_value)` with assertions:

`skip()` Declares a skipped test or test group. Test/s is/are never run.

`only()` Declares an exclusive test or test group that will be executed. If used, all other tests are skipped.

### `Example↓`


Expand All @@ -143,6 +145,16 @@ test.skip('description', () => {})
describe.skip('description', () => {})
```

```js
test.only('description', () => {
// Body of the only test that will be executed
})
//or
describe.only('description', () => {
// Body of the only test group that will be executed
})
```

---

## Context options
Expand Down
24 changes: 24 additions & 0 deletions src/core/context.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ export const describe = (name, optionsOrBody, body) => {
}
}

describe.only = (name, optionsOrBody, body) => {
const options = typeof optionsOrBody === 'object' ? optionsOrBody : {}
const actualBody = typeof optionsOrBody === 'function' ? optionsOrBody : body
const parentDescribe = currentDescribe
currentDescribe = makeDescribe(name, { ...options, focus: true })
actualBody()
currentDescribe = {
...parentDescribe,
children: [...parentDescribe.children, currentDescribe],
}
}

export const test = (name, optionsOrBody, body) => {
const options = typeof optionsOrBody === 'object' ? optionsOrBody : {}
const actualBody = typeof optionsOrBody === 'function' ? optionsOrBody : body
Expand All @@ -71,6 +83,18 @@ export const test = (name, optionsOrBody, body) => {
}
}

test.only = (name, optionsOrBody, body) => {
const options = typeof optionsOrBody === 'object' ? optionsOrBody : {}
const actualBody = typeof optionsOrBody === 'function' ? optionsOrBody : body
currentDescribe = {
...currentDescribe,
children: [
...currentDescribe.children,
{ ...makeTest(name, actualBody, options.timeout, options.tags, options.retry), focus: true },
],
}
}

export const skip = (name) => {
printSkippedMsg(name)
}
Expand Down
31 changes: 31 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,37 @@ type Options = {
* @param callback A callback that is run immediately when calling test(name, optionsOrBody, callback)
*/
skip(name: string, optionsOrBody: {}, body: {}): void
/**
* Declares an exclusive test group.
* Only the tests in this group are run, and all other tests are skipped.
* - `describe.only(title)`
* - `describe.only(title, details, callback)`
* - `test.only(title, callback)`
*
* **Usage**
*
* ```js
* describe.only('focused group', () => {
* test('example', () => {
* // This test will run
* });
* });
* ```
* or
*
* ```js
* describe('example', () => {
* test.only('focused test', () => {
* // This test will run
* });
* });
* ```
*
* @param name Test title.
* @param optionsOrBody (Optional) Object with options
* @param callback A callback that is run immediately when calling test(name, optionsOrBody, callback)
*/
only(name: string, optionsOrBody?: {}, body?: {}): void;
}
/**
* Execute before each test case.
Expand Down
41 changes: 41 additions & 0 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ export const describe = (name, optionsOrBody, body) =>
*/
describe.skip = (name) => core.skip(name)

/**
* Declares an exclusive test group.
* Only the tests in this group are run, and all other tests are skipped.
* - `describe.only(title)`
* - `describe.only(title, details, callback)`
*
* **Usage**
*
* ```js
* describe.only('focused group', () => {
* test('example', () => {
* // This test will run
* });
* });
* ```
*
* @param name Test title.
* @param optionsOrBody (Optional) Object with options
* @param callback A callback that is run immediately when calling describe.only(name, optionsOrBody, callback)
*/
describe.only = (...args) => core.describe.only(...args)

/**
* Test a specification or test-case with the given title, test options and callback fn.
*
Expand Down Expand Up @@ -85,6 +107,25 @@ export const test = (name, optionsOrBody, body) =>
*/
test.skip = (name) => core.skip(name)

/**
* Declares an exclusive test.
* Only this test is executed, while all others are skipped.
* - `test.only(title, callback)`
*
* **Usage**
*
* ```js
* test.only('focused test', () => {
* // This test will run
* });
* ```
*
* @param name Test title.
* @param optionsOrBody (Optional) Object with options
* @param callback A callback that is run immediately when calling test.only(name, optionsOrBody, callback)
*/
test.only = (...args) => core.test.only(...args)

/**
* Execute before each test case.
*
Expand Down