Last active
November 29, 2023 17:23
-
-
Save unlocomqx/aa1bc1aa615773723e452d4c2061ab09 to your computer and use it in GitHub Desktop.
It's something like this
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { defineConfig } from 'cypress'; | |
import { seed } from './cypress/plugins/seed'; | |
import vitePreprocessor from 'cypress-vite'; | |
export default defineConfig({ | |
video: false, | |
e2e: { | |
baseUrl: 'http://localhost:5173', | |
specPattern: '**/*.cy.ts', | |
setupNodeEvents(on, config) { | |
on('task', { | |
seed: async ({ spec }) => { | |
return seed(spec); | |
} | |
}); | |
on( | |
'file:preprocessor', | |
vitePreprocessor({ | |
configFile: './cypress/vite.config.ts', | |
mode: 'development' | |
}) | |
); | |
return config; | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sample test calling a seed file | |
describe('Map', () => { | |
it('display locations', () => { | |
cy | |
.task('seed', { spec: 'locations' }) | |
.visit('/map') | |
.get(`[data-cy=marker]`).should('have.length', 10); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { exec } from 'child-process-promise'; | |
import * as fs from 'fs'; | |
import * as path from 'path'; | |
export async function seed(spec: string) { | |
const file = new URL(`../fixtures/sql/${spec}.sql`, import.meta.url); | |
if (!fs.existsSync(file.pathname)) { | |
// file not exists? create a snapshot. | |
await exportData(file.pathname); | |
} | |
if (spec !== 'reset') { | |
await seed('reset'); | |
} | |
const command = `psql -U postgres -f ${file.pathname} -d etransport_test`; | |
return exec(command); | |
} | |
async function exportData(pathname: string) { | |
const dir = path.dirname(pathname); | |
if (!fs.existsSync(dir)) { | |
fs.mkdirSync(dir, { recursive: true }); | |
} | |
const command = `pg_dump --dbname=etransport_test --schema=public --data-only --file=${pathname} --column-inserts --username=postgres --host=localhost --port=5432`; | |
console.log(command); | |
return exec(command); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment