Skip to content

Commit

Permalink
fix: ensure absolute directories in glob patterns are leading prior t…
Browse files Browse the repository at this point in the history
…o removal (#23368)

* fix: ensure absolute directories in glob patterns are leading prior to removal

* Removing errant slash
  • Loading branch information
tbiethman authored Aug 16, 2022
1 parent ae5cbb5 commit 937d4e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/data-context/src/sources/FileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export class FileDataSource {
// The working directory path may include characters that conflict with glob
// syntax (brackets, parentheses, etc.) and cause our searches to inadvertently fail.
// We scope our search to the working directory using the `cwd` globby option.
return globPattern.replace(cwd, '.')
if (globPattern.startsWith(cwd)) {
return globPattern.replace(cwd, '.')
}

return globPattern
})

const ignoreGlob = (globOptions?.ignore ?? []).concat('**/node_modules/**')
Expand Down
18 changes: 18 additions & 0 deletions packages/data-context/test/unit/sources/FileDataSource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ describe('FileDataSource', () => {
expect(files).to.have.length(2)
})

it('does not replace working directory in glob pattern if it is not leading', async () => {
// Create a redundant structure within the project dir matching its absolute path
// and write a new script in that location
const nestedScriptPath = path.join(projectPath, 'cypress', projectPath)

await fs.mkdirs(nestedScriptPath)
await fs.writeFile(path.join(nestedScriptPath, 'nested-script.js'), '')

// Verify that the glob pattern is not impacted if if contains directories equivalent
// to the working directory
let files = await fileDataSource.getFilesByGlob(
projectPath,
`./cypress${projectPath}/nested-script.js`,
)

expect(files).to.have.length(1)
})

it('finds files matching multiple patterns', async () => {
const files = await fileDataSource.getFilesByGlob(
projectPath,
Expand Down

5 comments on commit 937d4e7

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 937d4e7 Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.6.0/linux-x64/develop-937d4e7f738642b4d08496347c4b868864e2c758/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 937d4e7 Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.6.0/linux-arm64/develop-937d4e7f738642b4d08496347c4b868864e2c758/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 937d4e7 Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.6.0/win32-x64/develop-937d4e7f738642b4d08496347c4b868864e2c758/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 937d4e7 Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.6.0/darwin-x64/develop-937d4e7f738642b4d08496347c4b868864e2c758/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 937d4e7 Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.6.0/darwin-arm64/develop-937d4e7f738642b4d08496347c4b868864e2c758/cypress.tgz

Please sign in to comment.