Skip to content

Commit

Permalink
fix: Исправлен запуск конкретного теста в VSCode на Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitive committed Sep 14, 2021
1 parent 6356388 commit d682bbc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 9 additions & 2 deletions modules/codecept/src/commands/run/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const path = require('path')
const { getConfig, getTestsRootDir, createArgsArrayFromMap } = require('@csssr/e2e-tools/utils')
const {
getConfig,
getTestsRootDir,
createArgsArrayFromMap,
stripDirectoryNameCaseInsensitive,
} = require('@csssr/e2e-tools/utils')
const packageName = require('../../../package.json').name
const { generateGitHubWorkflow } = require('./generate-github-workflow')

Expand Down Expand Up @@ -46,7 +51,9 @@ const addRunCommand = (context) => {
[
'codeceptjs',
'run',
...(args.test ? [args.test.replace(path.join(testRoot, 'codecept/'), '')] : []),
...(args.test
? [stripDirectoryNameCaseInsensitive(args.test, path.join(testRoot, 'codecept/'))]
: []),
...createArgsArrayFromMap({
config: 'codecept/codecept.conf.js',
grep: args.testcase,
Expand Down
12 changes: 12 additions & 0 deletions modules/tools/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,17 @@ async function addAnyProjectFields(ctx, opts) {
})
}

// VSCode на Windowns прокидывает название директории с диском в нижнем регистре,
// а process.cwd() возвращает название диска в верхнем регистре. Поэтому обрезаем
// название пути не учитывая регистра
function stripDirectoryNameCaseInsensitive(filePath, directoryName) {
if (filePath.toLowerCase().slice(0, directoryName.length) == directoryName.toLowerCase()) {
return filePath.slice(directoryName.length)
}

throw new Error(`Could not remove directory prefix ${directoryName} from path ${filePath}`)
}

module.exports = {
getTestsRootDir,
getProjectRootDir,
Expand All @@ -306,4 +317,5 @@ module.exports = {
normalizeUrl,
falseToError,
addAnyProjectFields,
stripDirectoryNameCaseInsensitive,
}

0 comments on commit d682bbc

Please sign in to comment.