-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: search parent folders for split file (#157)
* feat: search parent folders for split file * add find timings test to CI * set the custom spec pattern
- Loading branch information
Showing
9 changed files
with
120 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
examples/timings-file/tests/cypress-tests/cypress.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { defineConfig } = require('cypress') | ||
const cypressSplit = require('../../../../src') | ||
|
||
module.exports = defineConfig({ | ||
e2e: { | ||
// baseUrl, etc | ||
supportFile: false, | ||
fixturesFolder: false, | ||
specPattern: 'e2e/*.cy.js', | ||
setupNodeEvents(on, config) { | ||
console.log('cwd is', process.cwd()) | ||
cypressSplit(on, config) | ||
// IMPORTANT: return the config object | ||
return config | ||
}, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
it('works A', () => {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
it('works B', () => {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
it('works C', () => {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"durations": [ | ||
{ | ||
"spec": "cypress/e2e/spec-a.cy.js", | ||
"duration": 100 | ||
}, | ||
{ | ||
"spec": "cypress/e2e/spec-b.cy.js", | ||
"duration": 100 | ||
}, | ||
{ | ||
"spec": "cypress/e2e/spec-c.cy.js", | ||
"duration": 1000 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// @ts-check | ||
|
||
const debug = require('debug')('cypress-split') | ||
const exists = require('fs').existsSync | ||
const { join, normalize } = require('path') | ||
|
||
function isGitRootFolder(folder) { | ||
const gitRoot = '.git' | ||
const full = join(folder, gitRoot) | ||
return exists(full) | ||
} | ||
|
||
/** | ||
* Finds the file using the current working directory or its parent | ||
* directories up to the Git root folder. | ||
* @param {string} filename File to find | ||
* @returns {string|undefined} found file path or undefined | ||
*/ | ||
function findFile(filename) { | ||
if (!filename) { | ||
throw new Error('Missing the filename') | ||
} | ||
|
||
let currentFolder = process.cwd() | ||
let found | ||
|
||
while (true) { | ||
const maybePath = join(currentFolder, filename) | ||
if (exists(maybePath)) { | ||
found = maybePath | ||
debug('found file %s', found) | ||
break | ||
} | ||
if (isGitRootFolder(currentFolder)) { | ||
debug('reached git root folder %s', currentFolder) | ||
debug('but could not find %s', filename) | ||
break | ||
} | ||
const parent = normalize(join(currentFolder, '..')) | ||
if (parent === currentFolder) { | ||
debug('reached top level folder %s', currentFolder) | ||
debug('but could not find tool %s', filename) | ||
break | ||
} | ||
currentFolder = parent | ||
} | ||
return found | ||
} | ||
|
||
module.exports = { findFile } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters