Skip to content

Commit

Permalink
implements a/b tests with vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrosGounis committed May 17, 2024
1 parent fb09840 commit 98225fd
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 17 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,27 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest

name: Deploy
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: "20"

- name: Install dependencies
run: yarn

- name: Run tests
id: run-tests
run: yarn test

- uses: actions/checkout@v3
- name: Deploy app
if: success()
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"private": true,
"scripts": {
"deploy": "wrangler publish",
"dev": "wrangler dev --env dev"
"dev": "wrangler dev --env dev",
"test": "vitest"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20231218.0",
Expand All @@ -13,6 +14,8 @@
"wrangler": "^2.19.0"
},
"dependencies": {
"tweetnacl": "^1.0.3"
"@cloudflare/vitest-pool-workers": "^0.2.11",
"tweetnacl": "^1.0.3",
"vitest": "1.3.0"
}
}
32 changes: 32 additions & 0 deletions src/explore/__tests__/explore.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { createExecutionContext, env, waitOnExecutionContext } from "cloudflare:test";
import { describe, expect, it } from "vitest";
import { VERSIONS } from "../../utils/versioning";
import worker from "../../worker";
import { Env } from "../../../worker-configuration";

const LOCAL_BASE_URL = 'http://localhost:8787'
const SERVICES_BASE_URL = 'https://services.kukai.app'

const ENDPOINTS_TO_TEST = [
`${VERSIONS.V1}explore`,
`${VERSIONS.V2}explore`,
]

describe("compares explore to production", () => {
ENDPOINTS_TO_TEST.forEach((endpoint) => {
it(`tests ${endpoint}`, async () => {
const localRequest = new Request(`${LOCAL_BASE_URL}${endpoint}`)
const externalRequest = fetch(`${SERVICES_BASE_URL}${endpoint}`)

const ctx = createExecutionContext()
const localResponse = await worker.fetch(localRequest, env as Env, ctx)
const externalResponse = await externalRequest
await waitOnExecutionContext(ctx)

const localJsonResponse = await localResponse.json() as any

Check failure on line 26 in src/explore/__tests__/explore.test.ts

View workflow job for this annotation

GitHub Actions / Deploy

src/explore/__tests__/explore.test.ts > compares explore to production > tests /v2/explore

SyntaxError: Unexpected token 'I', "Internal Error" is not valid JSON ❯ src/explore/__tests__/explore.test.ts:26:39
const externalJsonResponse = await externalResponse.json() as any

expect(localJsonResponse.data).toEqual(externalJsonResponse.data)
})
})
})
4 changes: 1 addition & 3 deletions src/onboarding/discover/handle-assets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { ROUTES } from "../../router"

const BASE_PATH = ROUTES.ONBOARDING_DISCOVER_ASSETS

export const REMAP: Record<string, string> = {
contract: 'contractAddresses',
contractAddress: 'contractAddresses',
Expand All @@ -18,7 +16,7 @@ const ASSETS = [

export async function handleAssets(request: Request): Promise<Response> {
const { pathname } = new URL(request.url)
const assetIndex = pathname.substring(BASE_PATH.length - 1)
const assetIndex = pathname.substring(ROUTES.ONBOARDING_DISCOVER_ASSETS.length - 1)

const index = Number(assetIndex)

Expand Down
26 changes: 14 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

/* Projects */
// "incremental": true, /* Enable incremental compilation */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"lib": ["es2021"] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
"lib": [
"es2021"
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
"jsx": "react" /* Specify what JSX code is generated. */,
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
Expand All @@ -22,7 +22,6 @@
// "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */

/* Modules */
"module": "es2022" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
Expand All @@ -31,16 +30,18 @@
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
"types": ["@cloudflare/workers-types"] /* Specify type package names to be included without being referenced in a source file. */,
"types": [
"@cloudflare/workers-types",
"@cloudflare/workers-types/experimental",
"@cloudflare/vitest-pool-workers"
] /* Specify type package names to be included without being referenced in a source file. */,
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
"resolveJsonModule": true /* Enable importing .json files */,
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */

/* JavaScript Support */
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */,
"checkJs": false /* Enable error reporting in type-checked JavaScript files. */,
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */

/* Emit */
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
Expand All @@ -65,14 +66,12 @@
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
"isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,
"allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */,
// "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,

/* Type Checking */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
Expand All @@ -93,9 +92,12 @@
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */

/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
},
"include": [
"./**/*.ts",
"../src/env.d.ts"
]
}
11 changes: 11 additions & 0 deletions vitest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";

export default defineWorkersConfig({
test: {
poolOptions: {
workers: {
wrangler: { configPath: "./wrangler.toml" },
},
},
},
});

0 comments on commit 98225fd

Please sign in to comment.