Ross Gerbasi
03/08/2022, 1:18 AMnpm run test
it can't find jest. Is this expected? If so do we need to install jest and configure TS for it ourselves now?thdxr
03/08/2022, 1:20 AMRoss Gerbasi
03/08/2022, 1:21 AMnpm run test
i am seeing unable to find jest. So after installing jest it is not able to deal with TS files. So do we also need to configure babel for our local tests?thdxr
03/08/2022, 1:21 AMRoss Gerbasi
03/08/2022, 1:21 AMthdxr
03/08/2022, 1:22 AMRoss Gerbasi
03/08/2022, 1:22 AMnpm i
same situationRoss Gerbasi
03/08/2022, 1:22 AMthdxr
03/08/2022, 1:24 AMRoss Gerbasi
03/08/2022, 1:24 AMthdxr
03/08/2022, 1:26 AMthdxr
03/08/2022, 1:26 AMthdxr
03/08/2022, 1:28 AMRoss Gerbasi
03/08/2022, 1:29 AMthdxr
03/08/2022, 1:29 AMRoss Gerbasi
03/08/2022, 1:30 AMthdxr
03/08/2022, 1:30 AMthdxr
03/08/2022, 1:30 AMconst config = {
collectCoverageFrom: ["./**/*.{js,jsx,ts,tsx}"],
testEnvironment: "node",
testMatch: [
"<rootDir>/**/__tests__/**/*.{js,jsx,ts,tsx}",
"<rootDir>/**/*.{spec,test}.{js,jsx,ts,tsx}",
],
transform: {
"\\.ts$": "esbuild-runner/jest",
"\\.js$": "esbuild-runner/jest",
},
transformIgnorePatterns: [
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
],
};
Ross Gerbasi
03/08/2022, 1:35 AMRoss Gerbasi
03/08/2022, 1:35 AMthdxr
03/08/2022, 1:37 AMRoss Gerbasi
03/08/2022, 1:37 AMRoss Gerbasi
03/08/2022, 1:38 AMRoss Gerbasi
03/08/2022, 1:38 AMthdxr
03/08/2022, 1:39 AM.env.test, .env.local, .env
thdxr
03/08/2022, 1:39 AMRoss Gerbasi
03/08/2022, 1:42 AMthdxr
03/08/2022, 1:48 AMthdxr
03/08/2022, 1:48 AMRoss Gerbasi
03/08/2022, 1:49 AMoutputs.json
to add them as ENVs as well. all in globalSetup. pretty basic stuff.Ross Gerbasi
03/08/2022, 1:50 AMthdxr
03/08/2022, 1:51 AMRoss Gerbasi
03/08/2022, 1:51 AMRoss Gerbasi
03/08/2022, 1:53 AMresponse.json()
for is typed unknown instead of any. But it wont be the worst if I need to downgrade. Just seems a bit annoying as its all working except the tests. So much transpiling to just get down to the javascript hahaRoss Gerbasi
03/08/2022, 3:26 AMRoss Coundon
03/08/2022, 7:50 AMTypeError: Cannot read property 'someFunc' of undefined
Ross Coundon
03/08/2022, 7:55 AMesbuild-runner.config.js
just haven’t worked out what it is yetRoss Coundon
03/08/2022, 7:57 AMesbuild: {
target: 'esnext',
},
might do it but noRoss Gerbasi
03/08/2022, 7:59 AMRoss Coundon
03/08/2022, 8:00 AMRoss Gerbasi
03/08/2022, 8:04 AM"test": "vitest run -r test"
then I just added a vitest.config.ts
in my test folder. added a globalSetup.ts
and put it in the config also a few custom paths I use (~
, etc) using vite's resolve:alias syntax.
If going ESM and typescript I ended up using
"module": "ES2022",
"moduleResolution": "Node",
So that VSCode was cool with top level await and JSON modules.
Last step was adding
bundle: {
format: 'esm',
},
to the defaultFunctionProps for my stack.Ross Coundon
03/08/2022, 8:05 AMRoss Gerbasi
03/08/2022, 8:06 AMimport path from 'path'
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globalSetup: path.resolve(__dirname, 'globalSetup.ts'),
},
resolve: {
alias: {
'~': path.resolve(__dirname, '..', 'src'),
'~schema': path.resolve(__dirname, '..', 'schema'),
'~test': path.resolve(__dirname),
},
},
})
Ross Gerbasi
03/08/2022, 8:06 AMRoss Coundon
03/08/2022, 8:07 AMthdxr
03/08/2022, 1:32 PMthdxr
03/08/2022, 1:32 PMRoss Coundon
03/08/2022, 2:23 PMRoss Gerbasi
03/08/2022, 2:24 PMthdxr
03/08/2022, 2:25 PMthdxr
03/08/2022, 2:26 PMRoss Gerbasi
03/08/2022, 2:27 PMsst add jest
or some kind of magicRoss Coundon
03/08/2022, 2:27 PMSomething went wrong installing the "sharp" module Module did not self-register
I tried marking it as external but same issue. Also had a weird V8 error which I haven’t tracked down
FATAL ERROR: v8::FromJust Maybe value is Nothing
thdxr
03/08/2022, 2:30 PMRoss Gerbasi
03/08/2022, 2:34 PMthdxr
03/08/2022, 2:34 PMRoss Gerbasi
03/08/2022, 2:35 PMimport { describe, expect, it } from 'vitest'
import sharp from 'sharp'
describe('Sharp Test', () => {
it('Should test sharp', async () => {
const { info } = await sharp({
create: {
width: 24,
height: 48,
channels: 4,
background: { r: 255, g: 0, b: 0, alpha: 0.5 },
},
})
.rotate(90)
.toBuffer({ resolveWithObject: true })
expect(info.width).toBe(48)
expect(info.height).toBe(24)
})
})
Ross Gerbasi
03/08/2022, 2:35 PMRoss Coundon
03/08/2022, 2:37 PMRoss Coundon
03/08/2022, 2:37 PMRoss Gerbasi
03/08/2022, 2:38 PMRoss Gerbasi
03/08/2022, 2:40 PMSharp.class.ts
import sharp from 'sharp'
export default class SharpThing {
static async rotateThatThing() {
const { info } = await sharp({
create: {
width: 24,
height: 48,
channels: 4,
background: { r: 255, g: 0, b: 0, alpha: 0.5 },
},
})
.rotate(90)
.toBuffer({ resolveWithObject: true })
return info
}
}
sharp.test.ts
import { describe, expect, it } from 'vitest'
import SharpThing from '~/Sharp.class'
describe('Sharp Test', () => {
it('Should test sharp', async () => {
const info = await SharpThing.rotateThatThing()
expect(info.width).toBe(48)
expect(info.height).toBe(24)
})
})
Ross Gerbasi
03/08/2022, 2:40 PM~/
for me is just src/
Ross Gerbasi
03/08/2022, 2:41 PM"sharp": "^0.30.2",
in my package json as well, maybe if that's a difference?Ross Coundon
03/08/2022, 3:05 PM"sharp": "0.29.3",
so that’s a difference, waiting on an update to this to upgrade (submitted a PR a while back but no feedback) - anyway, this means sharp is a devDependency for usRoss Coundon
03/08/2022, 3:05 PMRoss Gerbasi
03/08/2022, 3:06 PMRoss Coundon
03/08/2022, 3:08 PMRoss Gerbasi
03/08/2022, 3:09 PMRoss Gerbasi
03/08/2022, 3:10 PMRoss Coundon
03/08/2022, 3:35 PM--ignore-scripts=false
I’ve also deleted node_modules and package-lock.json but still the same, very odd indeed.