Skip to content

Commit 2c32d0d

Browse files
author
DavertMik
committed
fixed pause finishing, added suggest for empty run, included fuse.js for better search
1 parent b7d32f7 commit 2c32d0d

File tree

8 files changed

+355
-254
lines changed

8 files changed

+355
-254
lines changed

lib/codecept.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class Codecept {
111111
runHook(require('./listener/globalTimeout'))
112112
runHook(require('./listener/globalRetry'))
113113
runHook(require('./listener/exit'))
114+
runHook(require('./listener/emptyRun'))
114115

115116
// custom hooks (previous iteration of plugins)
116117
this.config.hooks.forEach(hook => runHook(hook))

lib/listener/emptyRun.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const figures = require('figures')
2+
const Container = require('../container')
3+
const event = require('../event')
4+
const output = require('../output')
5+
6+
module.exports = function () {
7+
let isEmptyRun = true
8+
9+
event.dispatcher.on(event.test.before, test => {
10+
isEmptyRun = false
11+
})
12+
13+
event.dispatcher.on(event.all.result, () => {
14+
if (isEmptyRun) {
15+
const mocha = Container.mocha()
16+
17+
if (mocha.options.grep) {
18+
const Fuse = require('fuse.js')
19+
20+
output.print()
21+
output.print('No tests found by pattern: ' + mocha.options.grep)
22+
23+
const allTests = []
24+
mocha.suite.suites.forEach(suite => {
25+
suite.tests.forEach(test => {
26+
allTests.push(test.fullTitle())
27+
})
28+
})
29+
30+
const fuse = new Fuse(allTests, {
31+
includeScore: true,
32+
threshold: 0.6,
33+
caseSensitive: false,
34+
})
35+
36+
const results = fuse.search(mocha.options.grep.toString())
37+
38+
if (results.length > 0) {
39+
output.print()
40+
output.print('Maybe you wanted to run one of these tests?')
41+
results.forEach(result => {
42+
output.print(figures.checkboxOff, output.styles.log(result.item))
43+
})
44+
45+
output.print()
46+
output.print(output.styles.debug('To run the first test use the following command:'))
47+
output.print(output.styles.bold('npx codeceptjs run --debug --grep "' + results[0].item + '"'))
48+
}
49+
}
50+
if (process.env.CI) {
51+
output.print()
52+
output.error('No tests were executed. Failing on CI')
53+
process.exitCode = 1
54+
}
55+
}
56+
})
57+
}

lib/mocha/factory.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const fs = require('fs')
44
const reporter = require('./cli')
55
const gherkinParser = require('./gherkin')
66
const output = require('../output')
7-
const { genTestId } = require('../utils')
87
const ConnectionRefused = require('../helper/errors/ConnectionRefused')
98

109
const scenarioUi = fsPath.join(__dirname, './ui.js')
@@ -45,8 +44,6 @@ class MochaFactory {
4544
let missingFeatureInFile = []
4645
const seenTests = []
4746
mocha.suite.eachTest(test => {
48-
test.uid = genTestId(test)
49-
5047
const name = test.fullTitle()
5148
if (seenTests.includes(test.uid)) {
5249
dupes.push(name)

lib/mocha/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const Test = require('mocha/lib/test')
22
const { test: testWrapper } = require('./asyncWrapper')
33
const { enhanceMochaSuite } = require('./suite')
4+
const { genTestId } = require('../utils')
45

56
/**
67
* Factory function to create enhanced tests
@@ -40,6 +41,7 @@ function enhanceMochaTest(test) {
4041
suite.addTest(testWrapper(this))
4142
test.tags = [...(test.tags || []), ...(suite.tags || [])]
4243
test.fullTitle = () => `${suite.title}: ${test.title}`
44+
test.uid = genTestId(test)
4345
}
4446

4547
test.applyOptions = function (opts) {

lib/mocha/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Test as MochaTest, Suite as MochaSuite } from 'mocha'
33
declare global {
44
namespace CodeceptJS {
55
interface Test extends MochaTest {
6+
uid: string
67
title: string
78
tags: string[]
89
steps: string[]

0 commit comments

Comments
 (0)