Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed pause finishing, added suggest for empty run, included fuse.js … #4713

Merged
merged 9 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions lib/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class Codecept {
runHook(require('./listener/globalTimeout'))
runHook(require('./listener/globalRetry'))
runHook(require('./listener/exit'))
runHook(require('./listener/emptyRun'))

// custom hooks (previous iteration of plugins)
this.config.hooks.forEach(hook => runHook(hook))
Expand Down
57 changes: 57 additions & 0 deletions lib/listener/emptyRun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const figures = require('figures')
const Container = require('../container')
const event = require('../event')
const output = require('../output')

module.exports = function () {
let isEmptyRun = true

event.dispatcher.on(event.test.before, test => {
isEmptyRun = false
})

event.dispatcher.on(event.all.result, () => {
if (isEmptyRun) {
const mocha = Container.mocha()

if (mocha.options.grep) {
const Fuse = require('fuse.js')

output.print()
output.print('No tests found by pattern: ' + mocha.options.grep)

const allTests = []
mocha.suite.suites.forEach(suite => {
suite.tests.forEach(test => {
allTests.push(test.fullTitle())
})
})

const fuse = new Fuse(allTests, {
includeScore: true,
threshold: 0.6,
caseSensitive: false,
})

const results = fuse.search(mocha.options.grep.toString())

if (results.length > 0) {
output.print()
output.print('Maybe you wanted to run one of these tests?')
results.forEach(result => {
output.print(figures.checkboxOff, output.styles.log(result.item))
})

output.print()
output.print(output.styles.debug('To run the first test use the following command:'))
output.print(output.styles.bold('npx codeceptjs run --debug --grep "' + results[0].item + '"'))
}
}
if (process.env.CI) {
output.print()
output.error('No tests were executed. Failing on CI')
process.exitCode = 1
}
}
})
}
3 changes: 0 additions & 3 deletions lib/mocha/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const fs = require('fs')
const reporter = require('./cli')
const gherkinParser = require('./gherkin')
const output = require('../output')
const { genTestId } = require('../utils')
const ConnectionRefused = require('../helper/errors/ConnectionRefused')

const scenarioUi = fsPath.join(__dirname, './ui.js')
Expand Down Expand Up @@ -45,8 +44,6 @@ class MochaFactory {
let missingFeatureInFile = []
const seenTests = []
mocha.suite.eachTest(test => {
test.uid = genTestId(test)

const name = test.fullTitle()
if (seenTests.includes(test.uid)) {
dupes.push(name)
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Test = require('mocha/lib/test')
const { test: testWrapper } = require('./asyncWrapper')
const { enhanceMochaSuite } = require('./suite')
const { genTestId } = require('../utils')

/**
* Factory function to create enhanced tests
Expand Down Expand Up @@ -40,6 +41,7 @@ function enhanceMochaTest(test) {
suite.addTest(testWrapper(this))
test.tags = [...(test.tags || []), ...(suite.tags || [])]
test.fullTitle = () => `${suite.title}: ${test.title}`
test.uid = genTestId(test)
}

test.applyOptions = function (opts) {
Expand Down
1 change: 1 addition & 0 deletions lib/mocha/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Test as MochaTest, Suite as MochaSuite } from 'mocha'
declare global {
namespace CodeceptJS {
interface Test extends MochaTest {
uid: string
title: string
tags: string[]
steps: string[]
Expand Down
Loading
Loading