Skip to content

Commit

Permalink
feat: add edge function testing (#704)
Browse files Browse the repository at this point in the history
* feat: add netlify.toml to next example

* docs(examples): add postinstall script to install root deps in CI deploys

* docs(examples): update appinfo to point to the netlify deployment if defined

* docs(examples): update appinfo to point to the netlify deployment

* docs(examples): update appinfo to point to the netlify deployment

* test: update example tests

* chore: prettier

* test: add edge function test

* test: make sure the nextjs test call refresh to check edge compatibility
  • Loading branch information
porcellus authored Sep 29, 2023
1 parent 16d73e1 commit 64111cc
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 12 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/test-edge-function.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Test edge function compatibility"
on: push
jobs:
test:
runs-on: ubuntu-latest
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.netlify_auth_token }}
defaults:
run:
working-directory: examples/next/with-emailpassword
steps:
- uses: actions/checkout@v2
- run: echo $GITHUB_REF_NAME
- run: npm install git+https://github.com:supertokens/supertokens-node.git#$GITHUB_SHA
- run: npm install
- run: npm install [email protected] [email protected] puppeteer@^11.0.0 isomorphic-fetch@^3.0.0
- run: |
(netlify deploy --json --auth=$NETLIFY_AUTH_TOKEN > deployInfo.json) && ( \
(echo "=========== Test attempt 1 ===========" && npx mocha --no-config --timeout 80000 test/**/*.test.js) || \
(echo "=========== Test attempt 2 ===========" && npx mocha --no-config --timeout 80000 test/**/*.test.js) || \
(echo "=========== Test attempt 3 ===========" && npx mocha --no-config --timeout 80000 test/**/*.test.js) \
)
- name: The job has failed
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: screenshots
path: ./**/*screenshot.jpeg
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

## [16.0.1] - 2023-09-25
## [16.2.1] - 2023-09-25

### Changes

Expand Down
3 changes: 2 additions & 1 deletion examples/aws/with-emailpassword/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ describe("SuperTokens Example Basic tests", function () {
]);
await submitForm(page);
await page.waitForNavigation();
const user = await EmailPassword.getUserByEmail("public", email);
const userList = await SuperTokensNode.listUsersByAccountInfo("public", { email });
const user = userList[0];
const callApiBtn = await page.waitForSelector(".sessionButton");
let setAlertContent;
let alertContent = new Promise((res) => (setAlertContent = res));
Expand Down
3 changes: 2 additions & 1 deletion examples/express/with-emailpassword/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ describe("SuperTokens Example Basic tests", function () {
{ name: "password", value: testPW },
]);
await submitForm(page);
const user = await EmailPassword.getUserByEmail("public", email);
const userList = await SuperTokensNode.listUsersByAccountInfo("public", { email });
const user = userList[0];
const callApiBtn = await page.waitForSelector(".sessionButton");
let setAlertContent;
let alertContent = new Promise((res) => (setAlertContent = res));
Expand Down
3 changes: 2 additions & 1 deletion examples/fastify/with-emailpassword/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ describe("SuperTokens Example Basic tests", function () {
{ name: "password", value: testPW },
]);
await submitForm(page);
const user = await EmailPassword.getUserByEmail("public", email);
const userList = await SuperTokensNode.listUsersByAccountInfo("public", { email });
const user = userList[0];
const callApiBtn = await page.waitForSelector(".sessionButton");
let setAlertContent;
let alertContent = new Promise((res) => (setAlertContent = res));
Expand Down
3 changes: 2 additions & 1 deletion examples/hapi/with-emailpassword/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ describe("SuperTokens Example Basic tests", function () {
]);
await submitForm(page);
await page.waitForNavigation();
const user = await EmailPassword.getUserByEmail("public", email);
const userList = await SuperTokensNode.listUsersByAccountInfo("public", { email });
const user = userList[0];
const callApiBtn = await page.waitForSelector(".sessionButton");
let setAlertContent;
let alertContent = new Promise((res) => (setAlertContent = res));
Expand Down
3 changes: 2 additions & 1 deletion examples/koa/with-emailpassword/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ describe("SuperTokens Example Basic tests", function () {
{ name: "password", value: testPW },
]);
await submitForm(page);
const user = await EmailPassword.getUserByEmail("public", email);
const userList = await SuperTokensNode.listUsersByAccountInfo("public", { email });
const user = userList[0];
const callApiBtn = await page.waitForSelector(".sessionButton");
let setAlertContent;
let alertContent = new Promise((res) => (setAlertContent = res));
Expand Down
3 changes: 2 additions & 1 deletion examples/loopback/with-emailpassword/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ describe("SuperTokens Example Basic tests", function () {
]);
await submitForm(page);
await page.waitForNavigation();
const user = await EmailPassword.getUserByEmail("public", email);
const userList = await SuperTokensNode.listUsersByAccountInfo("public", { email });
const user = userList[0];
const callApiBtn = await page.waitForSelector(".sessionButton");
let setAlertContent;
let alertContent = new Promise((res) => (setAlertContent = res));
Expand Down
3 changes: 2 additions & 1 deletion examples/nest/with-emailpassword/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ describe("SuperTokens Example Basic tests", function () {
]);
await submitForm(page);
await page.waitForNavigation();
const user = await EmailPassword.getUserByEmail("public", email);
const userList = await SuperTokensNode.listUsersByAccountInfo("public", { email });
const user = userList[0];
const callApiBtn = await page.waitForSelector(".sessionButton");
let setAlertContent;
let alertContent = new Promise((res) => (setAlertContent = res));
Expand Down
3 changes: 2 additions & 1 deletion examples/next/with-emailpassword/config/appInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const port = process.env.APP_PORT || 3000;

const apiBasePath = "/api/auth/";

export const websiteDomain = process.env.APP_URL || process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${port}`;
export const websiteDomain =
process.env.APP_URL || process.env.NEXT_PUBLIC_APP_URL || process.env.URL || `http://localhost:${port}`;

export const appInfo = {
appName: "SuperTokens Demo App",
Expand Down
4 changes: 4 additions & 0 deletions examples/next/with-emailpassword/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build]
command = "NEXT_PUBLIC_APP_URL=$DEPLOY_URL npm run build"
functions = "netlify/functions"
publish = ".next"
1 change: 1 addition & 0 deletions examples/next/with-emailpassword/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/next/with-emailpassword/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"private": true,
"scripts": {
"postinstall": "../../../updateLibInExample",
"dev": "next dev",
"build": "next build",
"start": "next start"
Expand Down
28 changes: 25 additions & 3 deletions examples/next/with-emailpassword/test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,19 @@ const EmailPassword = require("supertokens-node/recipe/emailpassword");
// Run the tests in a DOM environment.
require("jsdom-global")();

const apiDomain = "http://localhost:3001";
const websiteDomain = "http://localhost:3000";
let deployInfo;

if (process.env.TEST_DEPLOYED_VERSION) {
deployInfo = require("../deployInfo.json");

if (!deployInfo.deploy_url) {
throw new Error("Deployment failed or json error. " + JSON.stringify(deployInfo));
}
}

const apiDomain = deployInfo?.deploy_url ?? "http://localhost:3000";
const websiteDomain = deployInfo?.deploy_url ?? "http://localhost:3000";

SuperTokensNode.init({
supertokens: {
// We are running these tests without running a local ST instance
Expand Down Expand Up @@ -80,8 +91,19 @@ describe("SuperTokens Example Basic tests", function () {
]);
await submitForm(page);
await page.waitForNavigation();
const user = await EmailPassword.getUserByEmail("public", email);
const userList = await SuperTokensNode.listUsersByAccountInfo("public", { email });
const user = userList[0];
const callApiBtn = await page.waitForSelector(".ProtectedHome_sessionButton__ihFAK");

// we save the cookies..
let originalCookies = (await page._client.send("Network.getAllCookies")).cookies;

// we set the old cookies with invalid access token
originalCookies = originalCookies.map((c) =>
c.name === "sAccessToken" || c.name === "st-access-token" ? { ...c, value: "broken" } : c
);
await page.setCookie(...originalCookies);

let setAlertContent;
let alertContent = new Promise((res) => (setAlertContent = res));
page.on("dialog", async (dialog) => {
Expand Down
3 changes: 3 additions & 0 deletions updateLibInExample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if ! [[ -z "${COMMIT_REF}" ]]; then
npm i git+$REPOSITORY_URL#$COMMIT_REF
fi

0 comments on commit 64111cc

Please sign in to comment.