Closed keinsell closed 2 years ago
Can you please share a sample repo demonstrating the issue (where ava CLI is running, but wallaby is not)? No real tests/source code is required, a copy of your project with all setup files and ./services/server/src/domain/metric/metric.spec
with a dummy content like:
import test from 'ava';
test('foo', t => {
t.pass();
});
should be enough for us to investigate.
wallaby
have problem the imports because errors are about these two packages.
import anyTest, { TestFn } from "ava";
import { faker } from "@faker-js/faker";
The rest of my test code looks like this.
import anyTest, { TestFn } from "ava";
import { faker } from "@faker-js/faker";
import { UserService } from "./user.service.js";
import { Prisma } from "prisma-client";
import { UserRepository } from "../../infrastructure/database/database.infra.js";
const test = anyTest as TestFn<{
userCreationData: Prisma.UserCreateInput;
}>;
test.beforeEach(async (t) => {
await UserRepository.deleteMany();
t.context.userCreationData = {
username: faker.internet.userName(),
password: faker.internet.password(),
};
});
// ! This is integration test which should be rewriten to Unit Test
test.serial("Should register new user", async (t) => {
// Import UserService
const userService = new UserService();
// Create new User
const user = await userService.registerUser({
username: t.context.userCreationData.username,
password: t.context.userCreationData.password,
}); //??
// Check if password of user is encrypted.
t.true(
user.user.password.startsWith("$argon2i$"),
"Password should be encrypted."
);
// Should return JWT token of user
t.is(
typeof user.token,
"string",
"Should return jsonwebtoken of created user."
);
});
// ! This is integration test which should be rewriten to Unit Test
test("Should login user", async (t) => {
// Import UserService
const userService = new UserService();
// Create new User
const user = await userService.registerUser({
username: t.context.userCreationData.username,
password: t.context.userCreationData.password,
});
// Login user
const userLogin = await userService.loginUser({
username: t.context.userCreationData.username,
password: t.context.userCreationData.password,
}); //??
// Check if user is authenticated
t.true(userLogin.isAuthenticated, "User should be authenticated.");
});
Can I provide a same repository or I should really create a new one? I can make repository public later today so there will be source code available.
My application will be open-source anyway, here you go: https://github.com/keinsell/neuronek/
Thanks for providing the repo.
There are a couple of ways to adjust your config to make it work:
symlinkNodeModules: false
in your Wallaby config, but if you update to the latest Wallaby core and set it to symlinkNodeModules: true
, it should work for you with ESM loader.symlinkNodeModules: true
, then you may make the following changes:module.exports = function (w) {
return {
...
files: [
// { pattern: "package.json", load: true },
- { pattern: "services/**/package.json", load: true },
+ { pattern: "services/**/package.json", ignore: true },
{ pattern: "services/**/src/**/*", load: true },
{ pattern: "services/**/src/**/*.spec.ts", ignore: true },
...
compilers: {
// "services/server/**/*.ts": w.compilers.typeScript({ module: "esnext" }),
"**/*.ts": w.compilers.typeScript({
- module: "esnext",
+ module: "commonjs",
moduleResolution: "node",
esModuleInterop: true,
}),
},
};
};
Configuration with commonjs
works but there is still problem with ESM
however, it's resolved for my actual needs. Thanks for help 😄
Awesome, thanks for the update!
Issue description or question
Wallaby doesn't really work in my monorepo. It found files but somehow it doesn't see like
node_modules
directory which causes errors.Wallaby diagnostics report