Nestjs can't resolve dependencies of the AppConfigService (Unit Testing) - testing

I am trying to set up Jest Unit Testing to my project, but I'm getting the following errors when trying to Unit Test:
Erro Message (Screenshot)
How do I fix this issue?

You need to add some sort of mock/provider for the ConfigService. At the very least, this will make the test attempt to work.
{
provide: ConfigService,
useValue: {},
}

When you initialise the AppConfigService in test, you need to wire up the providers as well. If you dont need to mock you can directly provide the class in the providers list. If you need mocking, you can use the following dummy code. Refer here for nestjs testing documentation
providers: [
{
provide: AppConfigService,
useValue: createMock<AppConfigService>({
<method_name>: jest.fn(),
}),
},

Related

Docusaurus getting mermaid up and running

[docusaurus] Newbie question: I am attempting to get mermaid up and running on my website, but am struggling to implement https://docusaurus.io/docs/markdown-features/diagrams. My docusaurus.config.js file is structured as follows:
const config = {
...
presets: [
...
],
themeConfig:
({
...
}),
}
module.exports = config;
Where should the block
markdown: {
mermaid: true,
},
themes: ['#docusaurus/theme-mermaid'].
be included in this structure?
I have attempted to include the stated block at all different points in the config.js file, but I either get a compile fail, or compile succeed, but no mermaid behaviour.
Thanks!
It is now working - I think the issue here was that the project I was attempting to use mermaid on was a 2.1.0 project. Once I updated it to 2.2.0 then things work as the documentation suggests.

Production build orderCore is missing

I had to manually upgrade from 3.2 to 4.2 and because I am developing a Angular library, I could not use the schematics to perform the update.
I have got it working on the development build. We are developing a feature library that targets the checkout (Payment Page and Order Confirmation Page) and it works fine.
With the production build (ng build --configuration production), the payment page works fine, but the Order Confirmation page is not working. it complains that orderCore feature is not configured properly.
Note: we are being redirected from an external site, back to the order confirmation page (after authorization). When the page loads, it shows the following error in the log and show a broken my account page.
core.js:6498 ERROR Error: Feature orderCore is not configured properly
at FacadeFactoryService.getResolver (spartacus-core.js:24825)
at FacadeFactoryService.create (spartacus-core.js:24867)
at facadeFactory (spartacus-core.js:24898)
at orderReturnRequestFacadeFactory (spartacus-order-root.js:13)
at Object.factory (spartacus-order-root.js:37)
at R3Injector.hydrate (core.js:11457)
at R3Injector.get (core.js:11276)
at NgModuleRef$1.get (core.js:25352)
at Object.get (core.js:25066)
at lookupTokenUsingModuleInjector (core.js:3354)
Anyone has an idea if we are missing some configuration in the feature modules?
import { NgModule } from '#angular/core';
import { checkoutTranslationChunksConfig, checkoutTranslations } from '#spartacus/checkout/assets';
import { CHECKOUT_FEATURE, CheckoutRootModule } from '#spartacus/checkout/root';
import { CmsConfig, I18nConfig, provideConfig } from '#spartacus/core';
#NgModule({
declarations: [],
imports: [
CheckoutRootModule,
],
providers: [provideConfig({
featureModules: {
[CHECKOUT_FEATURE]: {
module: () =>
import('#spartacus/checkout').then((m) => m.CheckoutModule),
}
},
} as CmsConfig),
provideConfig({
i18n: {
resources: checkoutTranslations,
chunks: checkoutTranslationChunksConfig,
},
} as I18nConfig)
]
})
export class CheckoutFeatureModule {
}
My colleague has provided a proposal:
If you want to use Spartacus Order library, you need to create "order-feature.module.ts" for it. And by default core is bundled together with components. So, in your configuration, you need have this set: "[ORDER_CORE_FEATURE]: ORDER_FEATURE". So, the config is something like this:
const config: CmsConfig = {
featureModules: {
[ORDER_FEATURE]: {
cmsComponents: [
....
],
},
// by default core is bundled together with components
[ORDER_CORE_FEATURE]: ORDER_FEATURE,
},
};

How do I handle the new isCustomElement setup for using web components in Vue 3 when unit testing with Jest

I am trying to write unit tests for my Vue 3 app using web components.
I have Jest configured containing transform options:
// ...
"transform": {
".*\\.(vue)$": "vue-jest",
"^.+\\.js$": "babel-jest"
},
// ...
I need to use isCustomElement which is now required at compilation time, so I’ve added options based on the proposed solution in Vue3 docs like I did in webpack. I played around with it in the transform and global options. And also tried adding it to my babel.config.
// ...
"transform": {
".*\\.(vue)$": ["vue-jest", {
compilerOptions: {
isCustomElement: tag => tag === 'my-custom-component'
}
}],
"^.+\\.js$": "babel-jest"
},
// ...
However it’s still throwing a Vue warn when running tests:
[Vue warn]: Failed to resolve component: my-custom-component.
Any ideas how to make isCustomElement work with Jest? I am at a loss as to what I need to set up to get rid of the console warnings and properly render the web components. In Vue 2 I just had to add them to setupFiles directly.

Laravel Mix and Vue custom Loader (iView)

I'm kinda new to programming with frameworks like VueJs and webpack is completely new for me. Right now we are working with Laravel 5.6 and laravel mix. I don't know if vue-loader is already in laravel.mix but I'm using a Vue Component Framework called iView and I need to load a custom Loader according to their page how to set it up: https://www.iviewui.com/docs/guide/iview-loader-en
The problem is it just doesn't work.
Nothing gets rendered and I get this error everytime:
[Vue warn]: Failed to mount component: template or render function not
defined.
Here's my webpack.mix.js
mix.webpackConfig({
module: {
rules: [
{
test: /\.vue$/,
use: [
{
loader: 'vue-loader',
options: {
}
},
{
loader: 'iview-loader',
options: {
prefix: true
}
}
]
}
]
}
})
But when I remove the section with loader: 'vue-loader' then everything gets rendered as it should but the custom loader is still not working since I get errors like this when using the kebap case name.
[Vue warn]: Unknown custom element: - did you register the
component correctly? For recursive components, make sure to provide
the "name" option.
Anyone good at Laravel who knows how to solve this? Thanks in advance.
cheers

Sails hook passport

I'm trying to implement Passport strategies into a sails hook, like this I can share on multiple project.
When I try to log I have this error :
Error: passport.initialize() middleware not in use
at IncomingMessage.req.login.req.logIn (/Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails-hook-passport/node_modules/passport-github/node_modules/passport-oauth/node_modules/passport/lib/passport/http/request.js:30:30)
at /Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails-hook-passport/api/controllers/AuthController.js:163:11
at Strategy.strategy.success (/Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails-hook-passport/node_modules/passport/lib/middleware/authenticate.js:194:18)
at verified (/Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails-hook-passport/node_modules/passport-twitter/node_modules/passport-oauth1/lib/strategy.js:169:16)
at returnResults (/Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/basic.js:168:9)
at /Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/basic.js:74:16
at /Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/operations.js:82:7
at Object.async.each (/Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails/node_modules/async/lib/async.js:121:20)
at /Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/operations.js:425:11
at /Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/operations.js:564:5
at Object.async.each (/Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails/node_modules/async/lib/async.js:121:20)
at _buildChildOpts (/Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/operations.js:453:9)
at _execChildOpts (/Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/operations.js:421:8)
at /Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails/node_modules/waterline/lib/waterline/query/finders/operations.js:80:10
at bound (/Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails/node_modules/lodash/dist/lodash.js:957:21)
at applyInOriginalCtx (/Users/jaumard/IdeaProjects/HookPassportTest/node_modules/sails/node_modules/waterline/lib/waterline/utils/normalize.js:421:80)
I read that I have to add some middleware in config/http.js
middleware: {
passportInit : require('passport').initialize(),
passportSession : require('passport').session(),
order: [
'startRequestTimer',
'cookieParser',
'session',
'passportInit',
'passportSession',
'myRequestLogger',
'bodyParser',
'handleBodyParserError',
'compress',
'methodOverride',
'poweredBy',
'router',
'www',
'favicon',
'404',
'500'
]
}
All it's working after this but I'm under an installable hook and don't want to manually change http.js, is there a way to modify this from the hook ? Or fix the error without adding this.
If I understand correctly, you need to init passport.js in your middleware but want to avoid having to manually edit http.js in each of your projects. To do that you'd create an installable hook like so:
module.exports = function passware(sails) {
sails.config.http.middleware = {
passportInit : require('passport').initialize(),
passportSession : require('passport').session(),
order: [
'startRequestTimer',
'cookieParser',
'session',
'passportInit',
'passportSession',
'myRequestLogger',
'bodyParser',
'handleBodyParserError',
'compress',
'methodOverride',
'poweredBy',
'router',
'www',
'favicon',
'404',
'500'
]
}
return {};
}
To use it you simply copy the hook into your node_modules or npm publish and npm install it in your projects.