Skip to content

Commit

Permalink
changes made with martin
Browse files Browse the repository at this point in the history
  • Loading branch information
vincanger committed Apr 5, 2024
1 parent 3810b9b commit 62f82c8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ jobs:
path: ~/.npm
key: ${{ runner.os }}-node${{ steps.setup-node.outputs.node-version }}-node-modules-${{ hashFiles('app/package-lock.json') }}

# In order for the app to run we need to set env vars even if they aren't used
# this step sets mock env vars to pass the validation steps so the app can run
# in the CI environment. For vars that are actually used in tests, we set them in
# the GitHub secrets settings and access them in a step below.
- name: Setup Dummy Env Vars
run: |
cd app
Expand All @@ -54,7 +58,7 @@ jobs:
- name: Run Playwright tests
env:
# the e2e tests are testing parts of the app that need OPENAI_API_KEY, so we need to set it here
# The e2e tests are testing parts of the app that need OPENAI_API_KEY, so we need to set it here.
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
cd e2e-tests
Expand Down
3 changes: 3 additions & 0 deletions e2e-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
These are e2e tests.

(TODO: Make comment on installation, setup (env vars), running, etc.)
3 changes: 1 addition & 2 deletions e2e-tests/ci-start-app-and-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function spawn(name, cmd, args, done) {
console.log(`\x1b[0m\x1b[33m[${name}][err]\x1b[0m ${data}`);
});
proc.on('exit', done);

} catch (error) {
console.error(error);
}
Expand All @@ -36,7 +35,7 @@ function spawn(name, cmd, args, done) {
const cb = (code) => {
if (code !== 0) {
process.exit(code);
}
}
};
spawn('app', 'npm', ['run', 'e2e:start-app'], cb);
spawn('db', 'npm', ['run', 'e2e:start-db'], cb);
Expand Down
7 changes: 7 additions & 0 deletions e2e-tests/global-teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { execSync } from 'child_process';

// TODO add comment
export default function teardown() {
console.log('<> Running Globalteardown <>')
execSync('npm run e2e:cleanup-db');
};
2 changes: 1 addition & 1 deletion e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"e2e:prisma-db-setup": "npm run e2e:wait-for-app && mkdir -p prisma && cp ../app/.wasp/out/db/schema.prisma prisma/schema.prisma && prisma generate",
"_comment-on-e2e:cleanup-db": "NOTE: the name of the DB container, e.g. name=^wasp-dev-db-OpenSaaS-, is generated by wasp and will match the name of the app definition in your `main.wasp` file, e.g. `app OpenSaaS { }`",
"e2e:cleanup-db": "(docker container rm $(docker container ls -f name=^wasp-dev-db-OpenSaaS- -q) -f || true) && docker volume rm $(docker volume ls -f name=^wasp-dev-db-OpenSaaS- -q) -f || true",
"e2e:playwright": "playwright test",
"e2e:playwright": "npx playwright test",
"e2e:playwright:debug": "DEBUG=pw:webserver npx playwright test"
},
"author": "",
Expand Down
16 changes: 10 additions & 6 deletions e2e-tests/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ export default defineConfig({
},
],

// globalSetup: require.resolve('./global-setup'), // TODO add dummy env vars here
// globalTeardown: require.resolve('./global-teardown'),

// TODO: change this comment for local testing --
/**
* There seems to be a bug that keeps the webserver open after running tests locally https://github.com/microsoft/playwright/issues/11907
* causing errors when trying to run `wasp start` afterwards. To avoid this, we can run the webserver only on CI.
* For local development, we start the app manually with `wasp start` and then run `npx playwright test` to run the tests.
*/
webServer: {
command: 'npm run e2e:start',
// Wait for the backend to start
url: 'http://localhost:3001',
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000,
}
command: 'npm run e2e:start',
// Wait for the backend to start
url: 'http://localhost:3001',
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000,
}
});
3 changes: 3 additions & 0 deletions e2e-tests/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const createRandomUser = () => {
return { username, password };
};

// TODO: change hasPaid to subscriptionStatus
export const createLoggedInUserFixture = ({ hasPaid, credits }: Pick<User, 'hasPaid' | 'credits'>) =>
base.extend<{ loggedInPage: Page; testUser: User }>({
testUser: async ({}, use) => {
Expand All @@ -59,11 +60,13 @@ export const createLoggedInUserFixture = ({ hasPaid, credits }: Pick<User, 'hasP
loggedInPage: async ({ page, testUser }, use) => {
await signUserUp({ page, user: testUser });
await page.waitForURL('/demo-app');
// TODO: try running stripe webhook in CI
const user = await prisma.user.update({
where: { username: testUser.username },
data: { hasPaid: testUser.hasPaid, credits: testUser.credits },
});
await use(page);
// TODO: don't delete this data? is it necessary?
// clean up all that nasty data 🤮
await prisma.gptResponse.deleteMany({ where: { userId: user.id } });
await prisma.task.deleteMany({ where: { userId: user.id } });
Expand Down

0 comments on commit 62f82c8

Please sign in to comment.