Skip to content

Commit

Permalink
fix: Allow component tests with special characters in filepath (#25299)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-plummer authored Dec 29, 2022
1 parent 285e2b3 commit dc78750
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const makeImport = (file: Cypress.Cypress['spec'], filename: string, chunkName:
const magicComments = chunkName ? `/* webpackChunkName: "${chunkName}" */` : ''

return `"${filename}": {
shouldLoad: () => document.location.pathname.includes("${encodeURI(file.absolute)}"),
shouldLoad: () => decodeURI(document.location.pathname).includes("${file.absolute}"),
load: () => import("${file.absolute}" ${magicComments}),
absolute: "${file.absolute.split(path.sep).join(path.posix.sep)}",
relative: "${file.relative.split(path.sep).join(path.posix.sep)}",
Expand Down
34 changes: 34 additions & 0 deletions system-tests/test/webpack_dev_server_spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
import systemTests from '../lib/system-tests'
import Fixtures from '../lib/fixtures'
import path from 'path'
import globby from 'globby'
import { escapeRegExp } from 'lodash'

describe('@cypress/webpack-dev-server', function () {
systemTests.setup()

const wdsPath = Fixtures.projectPath('webpack-dev-server')

systemTests.it('successfully loads and runs all specs', {
project: 'webpack-dev-server',
testingType: 'component',
spec: 'src/**/*',
browser: 'chrome',
expectedExitCode: 0,
onRun: async (exec) => {
// We do not expect any failures in this suite, but we need to check that we actually ran
// the tests that we expected to run to validate that WDS is properly parsing & loading
// tests with special filepaths

const { stdout } = await exec()

// Find all specs that should have been run as part of this system test
// by scanning filesystem using spec pattern
const files = await globby(path.join(wdsPath, 'src', '**', '*'))

// sanity check that we actually found some spec files
expect(files).to.have.length.greaterThan(0)

files.forEach((fileName) => {
// Parse out the subpath under 'src' that we expect to appear in the output results table
const expectedFileName = fileName
.replace(path.join(wdsPath, 'src'), '')
.replace(/^\/|\\/, '') // Remove leading path separator if one exists

// Pattern to match final output table entry
// Should include checkmark, filename, # of tests (1), and # of passes (1)
// ✔ [...bar].cy.js 17ms 1 1
const expectedPattern = new RegExp(`✔\\s+${escapeRegExp(expectedFileName)}\\s+\\d+ms\\s+1\\s+1`)

expect(stdout).to.match(expectedPattern)
})
},
})

systemTests.it('successfully loads and runs all specs with typescript config', {
Expand Down

4 comments on commit dc78750

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dc78750 Dec 29, 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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.2.1/linux-arm64/develop-dc7875064bc1ff0193d1f46ef9411f753cf39600/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dc78750 Dec 29, 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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.2.1/linux-x64/develop-dc7875064bc1ff0193d1f46ef9411f753cf39600/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dc78750 Dec 29, 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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.2.1/darwin-arm64/develop-dc7875064bc1ff0193d1f46ef9411f753cf39600/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dc78750 Dec 29, 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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.2.1/darwin-x64/develop-dc7875064bc1ff0193d1f46ef9411f753cf39600/cypress.tgz

Please sign in to comment.