reset cypress database
This commit is contained in:
parent
df747d9c69
commit
7fc8c37037
2 changed files with 28 additions and 2 deletions
|
|
@ -1,6 +1,25 @@
|
||||||
|
import { execFileSync } from 'node:child_process'
|
||||||
|
import { dirname, resolve } from 'node:path'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
import { defineConfig } from 'cypress'
|
import { defineConfig } from 'cypress'
|
||||||
import createBundler from '@bahmutov/cypress-esbuild-preprocessor'
|
import createBundler from '@bahmutov/cypress-esbuild-preprocessor'
|
||||||
|
|
||||||
|
const configDirectory = dirname(fileURLToPath(import.meta.url))
|
||||||
|
const backendDirectory = resolve(configDirectory, '../../backend')
|
||||||
|
|
||||||
|
function resetDatabase() {
|
||||||
|
execFileSync(
|
||||||
|
'php',
|
||||||
|
['artisan', 'migrate:fresh', '--seed', '--force'],
|
||||||
|
{
|
||||||
|
cwd: backendDirectory,
|
||||||
|
stdio: 'inherit',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
e2e: {
|
e2e: {
|
||||||
baseUrl: 'http://localhost:5173',
|
baseUrl: 'http://localhost:5173',
|
||||||
|
|
@ -11,6 +30,9 @@ export default defineConfig({
|
||||||
screenshotOnRunFailure: false,
|
screenshotOnRunFailure: false,
|
||||||
setupNodeEvents(onEvent) {
|
setupNodeEvents(onEvent) {
|
||||||
onEvent('file:preprocessor', createBundler())
|
onEvent('file:preprocessor', createBundler())
|
||||||
|
onEvent('task', {
|
||||||
|
resetDatabase,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
// Loaded automatically before every spec file in cypress/e2e/.
|
beforeEach(() => {
|
||||||
// Intentionally minimal - add shared commands here when needed.
|
cy.task('resetDatabase')
|
||||||
|
cy.clearCookies()
|
||||||
|
cy.clearLocalStorage()
|
||||||
|
})
|
||||||
|
|
||||||
export {}
|
export {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue