Currently, I am looking to experiment with SQL databases. I have SqlWorkbench installed and have mysql added in my package file.
However, I encountered an issue while attempting to run Cypress as SyntaxError: Unexpected token 'export'
The problem seems to be related to the code in cypress.config.ts (My local files contain data within the defineConfig)
import { defineConfig } from "cypress";
import mysql from 'mysql';
function queryTestDB(query,config) {
const connection = mysql.createConnection(config.env.db)
connection.connect()
return new Promise((resolve, reject) => {
connection.query(query, (error, results) => {
if (error) {
return reject(error)
}
connection.end()
return resolve(results)
})
})
}
export default defineConfig({
projectId: '...',
env: {
db: {
host: '...',
user: '...',
password: '...',
database: '...',
}
},
e2e: {
baseUrl: 'http://localhost...',
setupNodeEvents(on, config) {
on('task', {
queryDB(query) {
return queryTestDB(query,config)
}
})
}
},
});