Trying to run a "Hello world" component test with simplest HTTP dev server and no framework #32495
Unanswered
vfonic
asked this question in
Component Testing
Replies: 1 comment
-
I've found the issue. I followed the documentation and added Cypress documentation example implementation of client-script.js
const CypressInstance = (window.Cypress = parent.Cypress)
const devServerPublicPathRoute = CypressInstance.config(
'devServerPublicPathRoute'
)
let importPromise = Promise.resolve()
// If you do not bundle your support file along with the tests,
// you need to add a separate import statement for the support file.
const supportFilePath = CypressInstance.config('supportFile')
if (supportFilePath) {
const relative = supportFilePath.replace(
CypressInstance.config('projectRoot'),
''
)
importPromise = importPromise.then(
() => import(`${devServerPublicPathRoute}${relative}`)
)
}
// load the spec - you can extend the load function to also load css
const { relative } = CypressInstance.spec
importPromise = importPromise.then(
() => import(`${devServerPublicPathRoute}/${relative}`)
)
// trigger loading the imports
CypressInstance.onSpecWindow(window, importPromise)
// then start the test process
CypressInstance.action('app:window:before:load', window) The above implementation doesn't work, because Fixed example client-script.js implementation
const CypressInstance = (window.Cypress = parent.Cypress)
const devServerPublicPathRoute = CypressInstance.config("devServerPublicPathRoute")
const importPromises = []
// If you do not bundle your support file along with the tests,
// you need to add a separate import statement for the support file.
const supportFilePath = CypressInstance.config("supportFile")
if (supportFilePath) {
const relative = supportFilePath.replace(CypressInstance.config("projectRoot"), "")
importPromises.push(() => import(`${devServerPublicPathRoute}${relative}`))
}
// load the spec - you can extend the load function to also load css
const { relative } = CypressInstance.spec
importPromises.push(() => import(`${devServerPublicPathRoute}/${relative}`))
// trigger loading the imports
CypressInstance.onSpecWindow(window, importPromises)
// then start the test process
CypressInstance.action("app:window:before:load", window) Here's the diff
const CypressInstance = (window.Cypress = parent.Cypress)
const devServerPublicPathRoute = CypressInstance.config("devServerPublicPathRoute")
- let importPromise = Promise.resolve()
+ const importPromises = []
// If you do not bundle your support file along with the tests,
// you need to add a separate import statement for the support file.
const supportFilePath = CypressInstance.config("supportFile")
if (supportFilePath) {
const relative = supportFilePath.replace(CypressInstance.config("projectRoot"), "")
- importPromise = importPromise.then(() => import(`${devServerPublicPathRoute}${relative}`))
+ importPromises.push(() => import(`${devServerPublicPathRoute}${relative}`))
}
// load the spec - you can extend the load function to also load css
const { relative } = CypressInstance.spec
- importPromise = importPromise.then(() => import(`${devServerPublicPathRoute}/${relative}`))
+ importPromises.push(() => import(`${devServerPublicPathRoute}/${relative}`))
// trigger loading the imports
- CypressInstance.onSpecWindow(window, importPromise)
+ CypressInstance.onSpecWindow(window, importPromises)
// then start the test process
CypressInstance.action("app:window:before:load", window) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I've been trying to setup the simplest possible Cypress component test with no bundler, no framework. Just a simple HTTP server, serving plain ol' HTML files - HTML layout file + mounted HTML component.
I'm also looking to be able to load CSS and JS files. Again, no magic here, just plain ol' CSS and plain ol' JS that listens to DOMContentLoaded.
I've added a simple
devServer
and it successfully loadscomponent-index.html
layout file. The spec files are correctly found as well. However,mount
function is never called.When I click on spec name in Cypress/Chrome, such as
simple-test.cy.js
, the test opens and hangs onYour tests are loading...
.Screenshots
Here's my implementation:
cypress.config.js
cypress/support/dev-server.js
cypress/support/commands.js
cypress/support/component.js
cypress/component/simple-test.cy.js
cypress/support/component-index.html
mount
function is never called, nor is anything inside thecypress/component/simple-test.cy.js
(describe
is not called).Cypress should raise some error in this case. How can I debug this?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions