• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

How can I require core NodeBB modules inside my test files, supposed to be executed using mocha/jest binaries?

Scheduled Pinned Locked Moved NodeBB Development
10 Posts 2 Posters 818 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Muhammad SaqibM Offline
    Muhammad SaqibM Offline
    Muhammad Saqib
    wrote on last edited by
    #1

    I have to write unit tests for our custom plugins, and the tests files will be run with jest/mocha binaries. The problem is that I cannot require NodeBB core modules inside my test files to mock/stub them. I have tried both require.main.require and module.parent.require, and get the "Cannot find module" error. Is there a way to do so?

    Muhammad SaqibM 1 Reply Last reply
    0
  • Muhammad SaqibM Offline
    Muhammad SaqibM Offline
    Muhammad Saqib
    replied to Muhammad Saqib on last edited by
    #2

    @PitaJ @julian anybody?

    PitaJP 1 Reply Last reply
    0
  • PitaJP Offline
    PitaJP Offline
    PitaJ Global Moderator Plugin & Theme Dev
    replied to Muhammad Saqib on last edited by
    #3

    @Muhammad-Saqib not currently possible to run tests using NodeBB modules. The way this has to be done is having the NodeBB test run the tests of your plugin.

    It's currently not supported, though. Please open an issue on GitHub requesting this feature.

    Muhammad SaqibM 1 Reply Last reply
    0
  • Muhammad SaqibM Offline
    Muhammad SaqibM Offline
    Muhammad Saqib
    replied to PitaJ on last edited by
    #4

    @PitaJ said in How can I require core NodeBB modules inside my test files, supposed to be executed using mocha/jest binaries?:

    The way this has to be done is having the NodeBB test run the tests of your plugin.

    This doesn't work either if your plugin/theme is having module.parent.require calls inside them. Any other solution?

    PitaJP 1 Reply Last reply
    0
  • PitaJP Offline
    PitaJP Offline
    PitaJ Global Moderator Plugin & Theme Dev
    replied to Muhammad Saqib on last edited by
    #5

    @Muhammad-Saqib it will work if you change them to use require.main.require. NodeBB should warn if your plugin uses module.parent.require because that method is deprecated.

    Your plugin will need to be activated for the routes and sockets and stuff to work, though.

    1 Reply Last reply
    0
  • Muhammad SaqibM Offline
    Muhammad SaqibM Offline
    Muhammad Saqib
    wrote on last edited by Muhammad Saqib
    #6

    @PitaJ said in How can I require core NodeBB modules inside my test files, supposed to be executed using mocha/jest binaries?:

    Your plugin will need to be activated for the routes and sockets and stuff to work, though.

    @PitaJ Actually I have a custom theme, which has extended the core router and there are a few endpoints which I want to write tests for. What I am not being able to figure out is that how I can load my custom theme when I run npm run test in NodeBB directory so that I could run tests for my custom endpoints. Please note that my theme is child of nodebb-theme-persona, can you please help me with this? Thanks

    Muhammad SaqibM 1 Reply Last reply
    0
  • Muhammad SaqibM Offline
    Muhammad SaqibM Offline
    Muhammad Saqib
    replied to Muhammad Saqib on last edited by
    #7

    @Muhammad-Saqib said in How can I require core NodeBB modules inside my test files, supposed to be executed using mocha/jest binaries?:

    @PitaJ Actually I have a custom theme, which has extended the core router and there are a few endpoints which I want to write tests for. What I am not being able to figure out is that how I can load my custom theme when I run npm run test in NodeBB directory so that I could run tests for my custom endpoints. Please note that my theme is child of nodebb-theme-persona, can you please help me with this? Thanks

    Anybody who can respond? @julian

    PitaJP 1 Reply Last reply
    0
  • PitaJP Offline
    PitaJP Offline
    PitaJ Global Moderator Plugin & Theme Dev
    replied to Muhammad Saqib on last edited by
    #8

    @Muhammad-Saqib it's usually customary to wait more than a day before bumping a thread.

    The process is too difficult to really describe here, it might be easier to just implement a feature where tests can be run than explain how to do it yourself.

    There's an issue for this as well:

    Plugins being able to hook into test runner · Issue #3321 · NodeBB/NodeBB

    We have spent a lot of time componentizing modules from NodeBB (for ex. moving Markdown, Composer, Sounds API, search, mentions, etc) out of core. That said, those components shouldn't be exempt from requiring tests especially since the ...

    favicon

    GitHub (github.com)

    Muhammad SaqibM 1 Reply Last reply
    0
  • Muhammad SaqibM Offline
    Muhammad SaqibM Offline
    Muhammad Saqib
    replied to PitaJ on last edited by
    #9

    @PitaJ said in How can I require core NodeBB modules inside my test files, supposed to be executed using mocha/jest binaries?:

    The process is too difficult to really describe here, it might be easier to just implement a feature where tests can be run than explain how to do it yourself.

    So I will have to create a PR to NodeBB core for this feature? There seems not to be another way?

    PitaJP 1 Reply Last reply
    0
  • PitaJP Offline
    PitaJP Offline
    PitaJ Global Moderator Plugin & Theme Dev
    replied to Muhammad Saqib on last edited by
    #10

    @Muhammad-Saqib I wasn't suggesting that you specifically implement it, just that you should wait until someone does. If you can implement it, then please do!

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development