Closed Bidek56 closed 2 years ago
Struggling with the same.
Especially lowdb 3.0.0 (which is purely esm) in combination with jest.
I have tried running it with yarn node --experimental-vm-modules $(yarn bin jest)
on node 16.x
I have switched to Playwright and it works fine.
low.spec.js
import { test, expect } from '@playwright/test';
import { Low, JSONFile } from 'lowdb'
test('lowdb test', async () => {
const adapter = new JSONFile("./db.json");
const db = new Low(adapter);
await db.read()
expect(db.data.users).toBeTruthy();
});
Thanks @Bidek56 , I'm gonna give that a try!
Playwright is neither working.
This simple example using Node 19.3 and this package.json works fine for me:
{
"name": "lowdb-test",
"version": "1.0.0",
"description": "Test of lowdb and jest",
"type": "module",
"scripts": {
"test": "playwright test",
"build": "rm -rf dist/ && tsc"
},
"author": "Darek",
"license": "ISC",
"devDependencies": {
"@playwright/test": "^1.29.1",
"@types/lowdb": "^1.0.11",
"playwright": "^1.29.1",
"typescript": "^4.9.4"
},
"dependencies": {
"lowdb": "5.0.5"
}
}
low.spec.js
import { test, expect } from '@playwright/test';
import { Low } from 'lowdb'
import { JSONFile } from 'lowdb/node'
test('lowdb test', async () => {
const adapter = new JSONFile("./db.json");
const db = new Low(adapter);
await db.read()
expect(db.data.users).toBeTruthy();
});
lowdb 1.0 worked fine with jest, but 3.0 does not seem to work with jest 27.5.1. Does anyone know how to fix it? Thx
My sample 3.0
index.test.ts
code:using jest 27.5.1, I get the following error:
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export * from './adapters/JSONFile.js';
I have tried the following babel.config.js: