lukeed / ley

(WIP) Driver-agnostic database migrations
MIT License
259 stars 14 forks source link

Version 0.7 causes segmentation fault with jest #18

Open brielov opened 3 years ago

brielov commented 3 years ago

I have a setup test file where I create a new database and run the migrations within a beforeAll block. With 0.6.0 it runs fine but with 0.7.0 it throws SIGSEGV.

I'm running node version 15.11.0

import "dotenv/config";

import { execSync } from "child_process";
import { up as migrate } from "ley";
import { nanoid } from "nanoid";

const database = (process.env.PGDATABASE = `test_${nanoid()}`);

beforeAll(async () => {
  execSync(`createdb ${database}`);
  await migrate({
    dir: "migrations",
    driver: "postgres",
  });
});

afterAll(() => {
  execSync(`dropdb ${database}`);
});
lukeed commented 3 years ago

Hey, thanks

This is going to be tricky because Jest is notorious right now for not handling ESM (as of now). Can you first try with a Node.js 14.x version & see if the issue continues? Odd-versions of Node.js are always experimental/active-development. I'm not current w/ the 15.x release changes, but I'd wager that ESM is affected in some way since it's the latest major addition to the language.

If the issue still persists, I'd recommend something like segfault-handler so that you can see what is actually throwing the error. Could be a postgres driver. Could be the on-the-fly-rewrite that Jest has/had. Could be something with native ESM loading.

There's a lot of big pieces at play here, so we'll have to tackle them one at a time.

karlhorky commented 3 years ago

Node 16 is out now too, if you want to upgrade to a major version instead of downgrading.

Jest 27+ has experimental ESM support, which has worked for me in a number of projects now: https://jestjs.io/docs/ecmascript-modules