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

Question: How to wrote Unit tests using plugin_test.js #220

Open
chrismatheson opened this issue Aug 23, 2022 · 1 comment
Open

Question: How to wrote Unit tests using plugin_test.js #220

chrismatheson opened this issue Aug 23, 2022 · 1 comment
Labels
pending author feedback Waiting for feeback from author

Comments

@chrismatheson
Copy link

from the docs

kong-js-pdk provides a mock framework to test plugin code correctness through jest.

there are examples in the repo - https://github.com/Kong/kong-js-pdk/blob/master/__tests__/js-hello.test.js

however when I try to setup something simple myself I seem to fall over at the first hurdle

Kong = require('kong-pdk');
Uncaught:
Error: Cannot find module '/Users/....../node_modules/kong-pdk/app.js'. Please verify that the package.json has a valid "main" entry

and I think this is actually a valid error because the current package.json shows app.js as the main entry point https://github.com/Kong/kong-js-pdk/blob/master/package.json#L5 and there are no app.js files in the repo.

Before I make a pull request to try and clean things up a little I just wanted to check im not missing something basic.

@fffonion
Copy link
Contributor

fffonion commented Nov 9, 2022

Hi @chrismatheson , you don't need to require("kong-pdk") either in the test or writing a plugin.
The kong instance is a fake object that exposes several type definitions, to allow you happy programming
with an IDE etc.

The entry point in package.json is indeed incorrect, we should remove it. PRs are welcomed!

@hanshuebner hanshuebner added the pending author feedback Waiting for feeback from author label Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending author feedback Waiting for feeback from author
Projects
None yet
Development

No branches or pull requests

3 participants