Skip to content

Commit

Permalink
use console.error so we can see in the debug logs; add test
Browse files Browse the repository at this point in the history
  • Loading branch information
astone123 committed Mar 23, 2023
1 parent a478d7d commit 6cecebc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
42 changes: 19 additions & 23 deletions npm/vite-dev-server/client/initCypressTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,28 @@

// Fetch a dynamic import and re-try 3 times with a 2-second back-off
async function importWithRetry (importFn) {
const isTextTerminal = CypressInstance.config('isTextTerminal')

try {
return await importFn()
} catch (error) {
if (isTextTerminal) {
for (let i = 0; i < 3; i++) {
await new Promise((resolve) => setTimeout(resolve, 1000 * 2 ** i))

let url

try {
// Get request URL from error message from original import
url = new URL(
error.message
.replace('Failed to fetch dynamically imported module: ', '')
.trim(),
)

// add a timestamp to the end of the URL to force re-load the module instead of using the cache
url.searchParams.set('t', `${+new Date()}`)

return await import(url.href)
} catch (e) {
console.log(`retrying import of ${url?.href}`)
}
for (let i = 0; i < 3; i++) {
await new Promise((resolve) => setTimeout(resolve, 1000 * 2 ** i))

let url

try {
// Get request URL from error message from original import
url = new URL(
error.message
.replace('Failed to fetch dynamically imported module: ', '')
.trim(),
)

// add a timestamp to the end of the URL to force re-load the module instead of using the cache
url.searchParams.set('t', `${+new Date()}`)

return await import(url.href)
} catch (e) {
console.error(`retrying import of ${url?.href}`)
}
}

Expand Down
15 changes: 15 additions & 0 deletions npm/vite-dev-server/cypress/e2e/vite-dev-server.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ describe('Config options', () => {
expect(verifyFile).to.eq('OK')
})
})

it('retries importing support file if the import errors', () => {
cy.intercept('**/cypress/support/component.js', {
statusCode: 404,
})

cy.scaffoldProject('vite2.9.1-react')
cy.openProject('vite2.9.1-react', ['--config-file', 'cypress-vite.config.ts'])
cy.startAppServer('component')

cy.visitApp()
cy.contains('App.cy.jsx').click()
cy.waitForSpecToFinish()
cy.get('.passed > .num').should('contain', 2)
})
})

describe('sourcemaps', () => {
Expand Down

0 comments on commit 6cecebc

Please sign in to comment.