Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

haute-coture 4.x incompatible with Jest due to mo-walk #89

Open
Souvent22 opened this issue Dec 24, 2022 · 1 comment
Open

haute-coture 4.x incompatible with Jest due to mo-walk #89

Souvent22 opened this issue Dec 24, 2022 · 1 comment

Comments

@Souvent22
Copy link

Souvent22 commented Dec 24, 2022

Haute-Conture 4.2+ uses mo-walk.

There seem to be issues ( google search] in Node around dynamic imports. It seems to more prevalent with newer version of Node. Jest specifically will segfault on these. The line in question in mo-walk is:

https://github.com/devinivy/mo-walk/blob/main/lib/index.js#L157

Steps to Reproduce

  1. Run a simple hapipal init as outlined in the Quick Start
npm init @hapipal my-project
cd ./my-project
npm install
  1. Inside my-project add the following route at test at the following paths:
// <root>/test/ping.test.js
const Server = require('../server');

// Start application before running the test case
let server = null;
beforeAll(async () => {

});

// Stop application after running the test case
afterAll(async () => {
    if (server) {
        await server.stop();
    }
});

test('should ping tests', async () => {
    server = await Server.deployment();
    console.log('Server is running');
    const options = {
        method: 'GET',
        url: '/ping',
    };
    const data = await server.inject(options);
    expect(data.statusCode).toBe(200);
});
// <root>/lib/routes/ping.js
module.exports = {
    method: 'GET',
    path: '/ping',
    options: {
        auth: false,
        handler: async (request, h) => h.response({ status: 'OK' }),
    },
};
  1. Add Jest npm i jest
  2. Add test:jest to the package.json scripts area: "test:jest": "NODE_ENV=test jest --verbose",
  3. Run the test: npm run test:jest test/ping.test.js

I also recommend clearing out your node_modules and re-installing so you have a clean install.

This issue make it so that hapi-pal can't be used either as it uses HC, so this is a cascading effect. Lab doesn't seem to demonstrate this issue, however even though Jest does, I have also recreated this with Mocha.

@devinivy
Copy link
Member

For haute-couture to support ESM we need to use dynamic imports, so unfortunately I don't think there's a lot we can do on this side to fix the issue. This affects a bunch of projects, and sounds like some combination of the nodejs, v8, and jest teams are working it out together: nodejs/node#35889 jestjs/jest#11438

In the meantime there's a chance you can work around the issue by changing the contents of lib/index.js so that the file extension of the .hc.js file isn't inferred by haute-couture:

 exports.plugin = {
     pkg: Package,
     register: async (server, options) => {

         // Custom plugin code can go here

-        await HauteCouture.compose(server, options);
+        await HauteCouture.compose(server, options, {
+            amendments: require('./.hc.js')
+        });
     }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants