yes, your code, which uses the `cy.exec`
# help
h
yes, your code, which uses the
cy.exec
h
and how do you use
cy.exec
? i don't see it in this snippet
error you had in console says something about
docsUrl
i don't see it in the above snippet either
problematic code should exist somewhere in
beforeEach
hook of 'Dashborad' test suite, as error says
b
just a sec
Copy code
beforeEach(() => {
    cy.exec("npm run db:e2e:refresh", { timeout: 20000 });
    cy.clock(NOW);
  });
this is before each for whole test suite
and in nested describe blocks I have sth like:
some
Copy code
cy.request
, and
Copy code
cy.visit
docsUrl
is sth that cypress code tries to assign
h
and how does
npm run db:e2e:refresh
script looks like? have you tried clearing (remove it's code and leave a simple
console.log
to know the script is ran) the
refresh-database.ts
script to see if it's "guilty" in any way?
b
Copy code
cy.exec
not always fail. It won't fail when I'm running
it.only
so it's run. Maybe on subsequent runs it fails. It looks like:
Copy code
"db:e2e:refresh": "npm run typeorm-env apps/smartfm-e2e/src/scripts/refresh-database.ts",
Copy code
"typeorm-env": "ts-node -P apps/api/tsconfig.typeorm.json",
But if it fails, I guess cypress should handle it somehow if exit code is different than 0
h
have you checked what happens if you clear out the mentioned database script?
b
I'll check then
Now test don't stop on beforeEach but of course fail for another reason (lack of data)
I wonder if I should maybe then do some error handling inside the script
I've put whole execution into try-catch:
Copy code
try {
  refreshDatabase();
  console.log("refresh database");
} catch (e) {
  console.error(e);
}
but the error with
docsUrl
still occurs, maybe sth that happens earlier
I've put all logic that might cause trouble inside try-catch:
Copy code
// eslint-disable-next-line @typescript-eslint/no-var-requires
import * as de from "dotenv";
import { Client } from "pg";

async function refreshDatabase(): Promise<void> {
  de.config();
  const env = process.env;
  const client = new Client({
    user: env.TYPEORM_USERNAME,
    host: env.TYPEORM_HOST,
    database: "smartom",
    password: env.TYPEORM_PASSWORD,
    port: env.TYPEORM_PORT,
  });
  client.connect();

  await client.query(`DROP DATABASE IF EXISTS smartom_e2e WITH (FORCE)`);
  await client.query(`CREATE DATABASE smartom_e2e TEMPLATE smartom_e2e_tpl`);
  await client.end();
}

try {
  refreshDatabase();
  console.log("refresh database");
} catch (e) {
  console.error(e);
}
docsUrl
error still happens
sometimes 🙂
h
you don't wait for the
refreshDatabase
to do all it's async work, do you? https://gist.github.com/memee/56fc0227ea4802f1fd026bfcb4445182#file-refresh-database-ts-L21 try this
Copy code
js
try {
  await refreshDatabase();
  console.log("refresh database");
} catch (e) {
  console.error(e);
}
or
Copy code
js
refreshDatabase().catch(console.error)
which should log any caught error
b
right!!!
It might be that
h
what? is there error thrown by
refreshDatabase()
?
b
but I still get the same
docsUrl
error after few tests passed
I see that new cypress version uses
error?.docsUrl
no, actually it's the same when I look into transpiled code
3 Views