Skip to content

Commit cc6e2b0

Browse files
committed
fix tests
1 parent 1413142 commit cc6e2b0

19 files changed

+101
-32
lines changed

packages/editor/.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Note: keep this file in sync with env.ts
12
VITE_ENVIRONMENT=DEV
23
VITE_TYPECELL_BACKEND_WS_URL=ws://localhost:1234
34
VITE_TYPECELL_SUPABASE_URL=http://localhost:54321

packages/editor/.env.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
VITE_ENVIRONMENT=DEV
2+
VITE_TYPECELL_BACKEND_WS_URL=ws://localhost:1234
3+
VITE_TYPECELL_SUPABASE_URL=http://localhost:54321
4+
VITE_TYPECELL_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0
5+
VITE_MATRIX_HOMESERVER_URI=https://mx.typecell.org
6+
VITE_MATRIX_HOMESERVER_NAME=typecell.org

packages/editor/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@
115115
"lint": "eslint src",
116116
"test-watch": "vitest watch",
117117
"unittest:vitest": "vitest",
118-
"unittest:playwright": "playwright-test '**/BackgroundSyncer.browsertest.ts' --debug",
118+
"unittest:playwright": "playwright-test '**/*.browsertest.ts'",
119+
"test": "npm run unittest:playwright",
119120
"testFIXME": "npm run unittest:vitest",
120121
"vite:dev": "vite",
121122
"vite:build": "vite build --mode=$MODE",

packages/editor/src/app/supabase-auth/SupabaseSessionStore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SessionStore } from "../../store/local/SessionStore";
66
import { uniqueId } from "@typecell-org/common";
77
import * as Y from "yjs";
88
import type { Database } from "../../../../server/src/@types/schema";
9+
import { env } from "../../config/env";
910
import { TypeCellIdentifier } from "../../identifiers/TypeCellIdentifier";
1011
import {
1112
DefaultShorthandResolver,
@@ -105,7 +106,7 @@ export class SupabaseSessionStore extends SessionStore {
105106
isLoggedIn: computed,
106107
isLoaded: computed,
107108
});
108-
this.supabase = createClient<Database>(import.meta.env.VITE_TYPECELL_SUPABASE_URL, import.meta.env.VITE_TYPECELL_SUPABASE_ANON_KEY, {
109+
this.supabase = createClient<Database>(env.VITE_TYPECELL_SUPABASE_URL, env.VITE_TYPECELL_SUPABASE_ANON_KEY, {
109110
auth: {
110111
persistSession: persist,
111112
},

packages/editor/src/app/supabase-auth/routes/Login.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import { createClient } from "@supabase/supabase-js";
1010
import { SessionStore } from "../../../store/local/SessionStore";
1111
import { Logo } from "../../main/components/Logo";
1212

13+
import { env } from "../../../config/env";
1314
import AuthStyles from "./AuthStyles.module.css";
1415

1516
const supabase = createClient(
16-
import.meta.env.VITE_TYPECELL_SUPABASE_URL,
17-
import.meta.env.VITE_TYPECELL_SUPABASE_ANON_KEY
17+
env.VITE_TYPECELL_SUPABASE_URL,
18+
env.VITE_TYPECELL_SUPABASE_ANON_KEY
1819
);
1920

2021
export const Login = observer((props: { sessionStore: SessionStore }) => {

packages/editor/src/app/supabase-auth/routes/Register.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import {
77
ThemeSupa,
88
} from "@supabase/auth-ui-shared";
99
import { createClient } from "@supabase/supabase-js";
10+
import { env } from "../../../config/env";
1011
import { SessionStore } from "../../../store/local/SessionStore";
1112
import { Logo } from "../../main/components/Logo";
1213
import AuthStyles from "./AuthStyles.module.css";
1314

1415
const supabase = createClient(
15-
import.meta.env.VITE_TYPECELL_SUPABASE_URL,
16-
import.meta.env.VITE_TYPECELL_SUPABASE_ANON_KEY
16+
env.VITE_TYPECELL_SUPABASE_URL,
17+
env.VITE_TYPECELL_SUPABASE_ANON_KEY
1718
);
1819

1920
export const Register = observer((props: { sessionStore: SessionStore }) => {

packages/editor/src/config/config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { uri } from "vscode-lib";
2+
import { env } from "./env";
23

34
export const DEFAULT_PROVIDER: "matrix" | "supabase" = "supabase";
45

56
export const DEFAULT_HOMESERVER_URI = uri.URI.parse(
6-
import.meta.env?.VITE_MATRIX_HOMESERVER_URI
7+
env.VITE_MATRIX_HOMESERVER_URI
78
);
89

910
export const DEFAULT_IDENTIFIER_BASE =
@@ -23,7 +24,7 @@ export const DEFAULT_IDENTIFIER_BASE_STRING =
2324
DEFAULT_IDENTIFIER_BASE.toString().replace("://", ":");
2425

2526
export const MATRIX_CONFIG = {
26-
hsName: import.meta.env.VITE_MATRIX_HOMESERVER_NAME,
27+
hsName: env.VITE_MATRIX_HOMESERVER_NAME,
2728
hsUrl: DEFAULT_HOMESERVER_URI.toString(),
2829
isUrl: undefined as any, // "https://vector.im",
2930
defaultDeviceDisplayName: "TypeCell web",

packages/editor/src/config/env.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// We need to define the defaults for the dev env here,
2+
// because playwright-test doesn't seem to support .env files
3+
// (https://github.com/hugomrdias/playwright-test/issues/549)
4+
// NOTE: keep in sync with .env.development
5+
const devDefaults = {
6+
VITE_ENVIRONMENT: "development",
7+
VITE_TYPECELL_BACKEND_WS_URL: "ws://localhost:1234",
8+
VITE_TYPECELL_SUPABASE_URL: "http://localhost:54321",
9+
VITE_TYPECELL_SUPABASE_ANON_KEY:
10+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0",
11+
VITE_MATRIX_HOMESERVER_URI: "https://mx.typecell.org",
12+
VITE_MATRIX_HOMESERVER_NAME: "typecell.org",
13+
};
14+
15+
const passedInEnv = {
16+
VITE_ENVIRONMENT: import.meta.env?.VITE_ENVIRONMENT,
17+
VITE_TYPECELL_BACKEND_WS_URL: import.meta.env?.VITE_TYPECELL_BACKEND_WS_URL,
18+
VITE_TYPECELL_SUPABASE_URL: import.meta.env?.VITE_TYPECELL_SUPABASE_URL,
19+
VITE_TYPECELL_SUPABASE_ANON_KEY: import.meta.env
20+
?.VITE_TYPECELL_SUPABASE_ANON_KEY,
21+
VITE_MATRIX_HOMESERVER_URI: import.meta.env?.VITE_MATRIX_HOMESERVER_URI,
22+
VITE_MATRIX_HOMESERVER_NAME: import.meta.env?.VITE_MATRIX_HOMESERVER_NAME,
23+
};
24+
25+
export const env = import.meta.env?.VITE_ENVIRONMENT
26+
? passedInEnv
27+
: devDefaults;

packages/editor/src/config/security.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const ENVIRONMENT = import.meta.env.VITE_ENVIRONMENT;
1+
import { env } from "./env";
2+
3+
const ENVIRONMENT = env.VITE_ENVIRONMENT;
24
/*
35
Helper functions to ensure we're loading the application (host) and user-code frame (sandbox) from the correct domains
46
@@ -32,9 +34,7 @@ export function validateHostDomain() {
3234
}
3335

3436
export function validateSupabaseConfig() {
35-
if (
36-
import.meta.env.VITE_TYPECELL_SUPABASE_URL.includes("guzxrzrjknsekuefovon")
37-
) {
37+
if (env.VITE_TYPECELL_SUPABASE_URL.includes("guzxrzrjknsekuefovon")) {
3838
// only allow prod database on prod environment
3939
return ENVIRONMENT === "PROD";
4040
}

packages/editor/src/index.host.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { matrixAuthProvider } from "./app/matrix-auth/MatrixAuthProvider";
99
import { SupabaseSessionStore } from "./app/supabase-auth/SupabaseSessionStore";
1010
import { supabaseAuthProvider } from "./app/supabase-auth/supabaseAuthProvider";
1111
import { DEFAULT_PROVIDER } from "./config/config";
12+
import { env } from "./config/env";
1213
import { validateHostDomain, validateSupabaseConfig } from "./config/security";
1314
import { setMonacoDefaults } from "./runtime/editor";
1415
import { MonacoContext } from "./runtime/editor/MonacoContext";
@@ -21,7 +22,7 @@ import "./styles/index.css";
2122
(window as any).Buffer = Buffer;
2223
(window as any).process = process;
2324

24-
if (import.meta.env.DEV) {
25+
if (env.VITE_ENVIRONMENT === "development") {
2526
// disables error overlays
2627
// We make use of React Error Boundaries to catch exceptions during rendering of
2728
// user-defined react components. It's annoying (and slow) to get the React error overlay

0 commit comments

Comments
 (0)