Skip to content

Commit

Permalink
Merge pull request #15 from herbsjs/beta
Browse files Browse the repository at this point in the history
Only scenario
  • Loading branch information
jhomarolo authored Nov 22, 2023
2 parents bb5df83 + 58dfe5a commit c96ad65
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CD Build

on:
push:
branches: [ main ]
branches: [ main, next, beta, alpha ]

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI build

on:
pull_request:
branches: [main]
branches: [ main, next, beta, alpha ]

jobs:
build:
Expand Down
15 changes: 14 additions & 1 deletion .releaserc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
{
"branches": "main",
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"main",
"next",
"next-major",
{
"name": "beta",
"prerelease": true
},
{
"name": "alpha",
"prerelease": true
}
],
"repositoryUrl": "https://github.com/herbsjs/aloe",
"debug": "true",
"plugins": [
Expand Down
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,39 @@
# [2.3.0-beta.2](https://github.com/herbsjs/aloe/compare/v2.3.0-beta.1...v2.3.0-beta.2) (2023-07-27)


### Bug Fixes

* **lint:** fix lint error ([6fc20d0](https://github.com/herbsjs/aloe/commit/6fc20d059e71c50aec81a545f47ee506d5a6d6f3))
* **prettystack:** fix prettyStack when error is not a Error instance ([d73ff5f](https://github.com/herbsjs/aloe/commit/d73ff5fb1dc434e770546bc6b7bf849425fce52d))

# [2.3.0-beta.1](https://github.com/herbsjs/aloe/compare/v2.2.2-beta.3...v2.3.0-beta.1) (2023-05-12)


### Features

* **scenario:** only - run only scenarios marked as .only ([8ce67a0](https://github.com/herbsjs/aloe/commit/8ce67a023220cfe8679c43a7885d97072499cb46)), closes [#7](https://github.com/herbsjs/aloe/issues/7)

## [2.2.2-beta.3](https://github.com/herbsjs/aloe/compare/v2.2.2-beta.2...v2.2.2-beta.3) (2023-03-29)


### Bug Fixes

* **package.json:** fix export main ([08e01ed](https://github.com/herbsjs/aloe/commit/08e01edc5575d74a6ee1499a594ed156d93c8bcb))

## [2.2.2-beta.2](https://github.com/herbsjs/aloe/compare/v2.2.2-beta.1...v2.2.2-beta.2) (2023-03-29)


### Bug Fixes

* **depencency:** buchu version ([751ff23](https://github.com/herbsjs/aloe/commit/751ff235e81a7742af6595afd5c67dd22a5bc9ce))

## [2.2.2-beta.1](https://github.com/herbsjs/aloe/compare/v2.2.1...v2.2.2-beta.1) (2023-03-29)


### Bug Fixes

* **touch:** ping ([4b55fe9](https://github.com/herbsjs/aloe/commit/4b55fe9929b978a647ac89ba498fa3ff428e6208))

## [2.2.1](https://github.com/herbsjs/aloe/compare/v2.2.0...v2.2.1) (2023-03-20)


Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ const taskCountSpec = spec({
})
```

It is possible to have many `given` and `check` on the same scenario.
It is possible to have many `given` and `check` on the same scenario.



```javascript
const billingSpec = spec({
Expand All @@ -62,6 +64,17 @@ const billingSpec = spec({
}),
})
```
It's also possible to run `only` a specific scenario.

```javascript
const taskCountSpec = spec({
'Change count for the task': scenario.only({
'Given a valid task': given({ task: 'do it', count: 0 }),
'When increase count': when((ctx) => (ctx.count++)),
'Must have a increased count': check((ctx) => { assert.ok(ctx.count === 1) }),
}),
})
```

### Use Case Spec

Expand Down Expand Up @@ -174,7 +187,7 @@ const createUserSpec = spec({
}),
})
```
### Runner
The runner is responsible for executing the scenarios and showing the results.
Expand All @@ -201,7 +214,7 @@ await runner() // specsPath can be especified
- [ ] doc on web site
- [ ] CLI: doc `spec` command
- [ ] skip
- [ ] only
- [X] only
- [ ] todo / pending
- [ ] nested scenarios
- [ ] tests for runner
Expand Down
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "@herbsjs/aloe",
"version": "2.2.1",
"version": "2.3.0-beta.2",
"description": "Scenario description and test runner for Herbs",
"main": "./src/aloe.js",
"exports": {
".": "./src/aloe.js",
"./runner": "./src/runner/runner.js"
},
"scripts": {
Expand Down Expand Up @@ -38,7 +39,7 @@
"license": "MIT",
"homepage": "https://github.com/herbsjs/aloe#readme",
"peerDependencies": {
"@herbsjs/buchu": "2.1.0"
"@herbsjs/buchu": "^2.1.1"
},
"peerDependenciesMeta": {
"@herbsjs/buchu": {
Expand All @@ -47,7 +48,7 @@
},
"devDependencies": {
"@babel/eslint-parser": "^7.18.2",
"@herbsjs/buchu": "^1.6.2",
"@herbsjs/buchu": "^2.1.1",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/git": "^10.0.1",
Expand Down
6 changes: 6 additions & 0 deletions src/runner/prettyStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ const themes = {

function prettyStack({ error, theme = themes.herbs }) {

if (!(error instanceof Error)) {
/* eslint-disable no-console */
console.info(`\n `, chalk.ansi256(theme['main'])('Error:'), chalk.ansi256(theme['message'])(chalk.bgAnsi256(theme['backgroundMessage'])(error)), `\n`)
return
}

// Replace the error message with a colorized version
let messageStack = error.stack.replace(error.message, chalk.ansi256(theme['message'])(chalk.bgAnsi256(theme['backgroundMessage'])(error.message)))

Expand Down
19 changes: 18 additions & 1 deletion src/runner/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ async function runner({ specs, herbarium, specsPath, dependencies = {} }) {
return orderedGroup
}


async function showScenarios(spec, previousGroup, groupName, errorCount, successCount) {
const ret = await spec.run()
if (ret === state.ignored) return { previousGroup, errorCount, successCount }
const color = ret !== failed ? white : red
if (previousGroup !== groupName) {
if (groupName === undefinedGroup)
Expand All @@ -79,6 +79,8 @@ async function runner({ specs, herbarium, specsPath, dependencies = {} }) {

for (const scenario of spec.scenarios) {

if (scenario.state === state.ignored) continue

function countSamples(scenario) {
let count = 0
for (const sample of scenario.samples) {
Expand Down Expand Up @@ -147,6 +149,21 @@ async function runner({ specs, herbarium, specsPath, dependencies = {} }) {
return { errorCount, successCount }
}

function prepareForOnly() {
// build all the specs
specs.forEach(meta => meta.spec.build())

// if there is one or more specs with only, mark all the others as ignored
const hasOnly = Array.from(specs).some(([_, meta]) => meta.spec.only)
if (hasOnly) {
specs.forEach(meta => {
if (!meta.spec.only) meta.spec.ignore = true
})
}
}

prepareForOnly()

const usecasesGroup = groupSteps(specs)

for (const groupName in usecasesGroup) {
Expand Down
1 change: 1 addition & 0 deletions src/runningState.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ module.exports.state = Object.freeze({
done: 'done',
passed: 'passed',
failed: 'failed',
ignored: 'ignored',
})
17 changes: 14 additions & 3 deletions src/scenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ class SamplesExecution {


class Scenario {
constructor(description, body) {
constructor(description, body, options = {}) {
this.type = 'scenario'
this.state = state.ready
this.description = description
this.ignore = false
this._auditTrail = { type: this.type, state: this.state, description: this.description }
this._body = body
this.only = options.only
}

async run() {
Expand All @@ -138,6 +140,12 @@ class Scenario {
this.samples = intialized.filter(s => s.isSamples)
addBuiltinSample()

if(this.ignore) {
this.state = state.ignored
this._auditTrail.state = this.state
return this.state
}

for (const samples of this.samples) {
const execution = new SamplesExecution(this, samples)
samples.execution = execution
Expand Down Expand Up @@ -186,8 +194,11 @@ class Scenario {
}
}

const scenario = (body) => ({
create: (description) => { return new Scenario(description, body) }
const scenario = (body, options) => ({
create: (description) => { return new Scenario(description, body, options) }
})

scenario.only = (body, options) => scenario(body, Object.assign({}, options, { only: true }))


module.exports = { scenario }
Loading

0 comments on commit c96ad65

Please sign in to comment.