Skip to content

Commit

Permalink
add pyodide rules_engine whl test with vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
thadk committed Nov 22, 2023
1 parent bf0aa2f commit 17812a5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
32 changes: 32 additions & 0 deletions heat-stack/app/utils/pyodide.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expect, test } from 'vitest'
import * as pyodideModule from 'pyodide'

/* For this to pass, you must run
`pushd ../rules-engine && python3 -m venv venv && source venv/bin/activate && pip install -q build && python3 -m build && popd` */

/* Referenced https://github.com/epicweb-dev/full-stack-testing/blob/main/exercises/04.unit-test/02.solution.spies/app/utils/misc.error-message.test.ts of https://www.epicweb.dev/workshops/web-application-testing*/
test('pyodide loads', async () => {
const getPyodide = async () => {
// public folder:
return await pyodideModule.loadPyodide({
indexURL: 'public/pyodide-env/',
})
}
const runPythonScript = async () => {
const pyodide: any = await getPyodide()
// console.log(engine);
await pyodide.loadPackage('numpy')
await pyodide.loadPackage(
'../rules-engine/dist/rules_engine-0.0.1-py3-none-any.whl',
)
return pyodide
}
// consider running https://github.com/codeforboston/home-energy-analysis-tool/blob/main/rules-engine/tests/test_rules_engine/test_engine.py
const pyodide: any = await runPythonScript()
const result = await pyodide.runPythonAsync(`
from rules_engine import engine
out = engine.hdd(57, 60)
out`)
expect(result).toBe(3)
})
2 changes: 1 addition & 1 deletion heat-stack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"setup": "npm run build && prisma generate && prisma migrate deploy && prisma db seed && playwright install",
"start": "cross-env NODE_ENV=production node .",
"start:mocks": "cross-env NODE_ENV=production MOCKS=true tsx .",
"test": "vitest",
"test": "pushd ../rules-engine && python3 -m venv venv && source venv/bin/activate && pip install -q build && python3 -m build && popd && vitest",
"coverage": "vitest run --coverage",
"test:e2e": "npm run test:e2e:dev --silent",
"test:e2e:dev": "playwright test --ui",
Expand Down
4 changes: 2 additions & 2 deletions heat-stack/tests/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import closeWithGrace from 'close-with-grace'
import { passthrough, http } from 'msw'
import { setupServer } from 'msw/node'
import { handlers as githubHandlers } from './github.ts'
// import { handlers as githubHandlers } from './github.ts'
import { handlers as resendHandlers } from './resend.ts'

const miscHandlers = [
Expand All @@ -13,7 +13,7 @@ const miscHandlers = [
export const server = setupServer(
...miscHandlers,
...resendHandlers,
...githubHandlers,
// ...githubHandlers, /* commenting out to enable app/utils/pyodide.test.ts
)

server.listen({ onUnhandledRequest: 'warn' })
Expand Down

0 comments on commit 17812a5

Please sign in to comment.