Skip to content

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

@Souvent22

Description

@Souvent22

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions