serpapi-javascript is developed using Deno. Refer to
https://deno.land/manual/getting_started/installation to install Deno.
Ensure you're running at least Deno v1.28.3.
deno --version
deno upgrade # to upgrade to the latest versionInstall the appropriate extension for your preferred editor/IDE: https://deno.land/manual/getting_started/setup_your_environment. The extension "integrates directly to the Deno CLI using the language server protocol. This helps ensure that the information you get about your code aligns to how that code will work when you try to run it under the Deno CLI."1
If you use VSCode, use the following settings (.vscode/settings.json):
{
"deno.enablePaths": [
"mod.ts",
"version.ts",
"src",
"tests/*.ts",
"tests/engines/",
"scripts",
"examples/deno"
],
"deno.inlayHints.enumMemberValues.enabled": false,
"deno.inlayHints.functionLikeReturnTypes.enabled": false,
"deno.inlayHints.parameterNames.enabled": "none",
"deno.inlayHints.parameterTypes.enabled": false,
"deno.inlayHints.propertyDeclarationTypes.enabled": false,
"deno.inlayHints.variableTypes.enabled": false,
"[json]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "denoland.vscode-deno"
},
"[markdown]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "denoland.vscode-deno"
},
"[typescript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "denoland.vscode-deno"
}
}Subsequently, install the vscode_deno extension and you're good to go.
- Every new feature must have associated tests.
- Tests are to be added in the
tests/folder. - Use Deno's
bdd.tsmodule to write tests. It provides the typicalbeforeandafterhooks.
- When testing functionality that requires an API key, you need to ensure your API key is specified as an environment variable.
- Create a
.envfile with the following contents, replacingYOUR_API_KEYwith your API key for the appropriate environment.
SERPAPI_TEST_KEY=YOUR_API_KEY
- Note that for tests that require an API key, the test suite skips them if an
API key is not defined, e.g. the following test is ignored when no API key has
been set in the
.envfile.
it("getJson with api key from config", {
ignore: !HAS_API_KEY,
}, async () => {
...
});deno task test # Run tests
deno task test:watch # Run tests and in watch mode: https://deno.land/manual/getting_started/command_line_interface#watch-mode
deno task test:cov # Get test coverage by running testsTo run examples on your local source files, follow these steps.
- Run
deno task npmto build the files. - Update the respective example's
package.jsonto depend on the localserpapimodule instead,{ "dependencies": { "dotenv": "*", "serpapi": "../../../npm" }, "scripts": { "start": "node basic_example.js" } }
These test key functionality on different Node.js versions. They are ran on GitHub Actions, see the build workflow for more details.
To run these locally, follow these steps.
- Run
deno task npmto build the files. - Change directory to either the
commonjsoresmfolder. - Setup the intended Node.js version. For example, if you're using
nvm, you can runnvm use 14to run Node.js 14 for the current shell. - Run
npm i, thennpm test.
- Every exposed function must have associated JSDoc comments.
documentation.jsrelies on these JSDoc comments to generate documentation in Markdown.- Run the following to update
README.md.
deno task docs:genTypeScript types are generated from the backend code. Follow these steps to update the types.
- Run
bundle exec rails libraries:generate_ts_typesin the backend repository. - Replace everything in
src/engineswith the generated files fromtmp/ts/engines. - Update
mod.tswith the new engine exports fromtmp/ts/mod.ts.
- Ensure all associated tests have been added
- Ensure all tests pass
- Ensure all relevant documentation have been updated
- Ensure the changelog has been updated with your changes
Once you've done the above, create a pull request with a clear description. SerpApi project members will then review the request.
- Update changelog.
- Merge the associated PR and ensure the "Build" workflow succeeds.
- Update
version.tsbased on semantic versioning, e.g.1.2.0. - Push
version.ts. This triggers the "Release" workflow. - Verify that new versions have been released on npm and deno.land/x.