Skip to content

Commit

Permalink
Add website tests (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas authored Mar 8, 2024
1 parent f8561c0 commit ed36ba2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/test-website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test Website Builds

on: [push, pull_request]

permissions:
contents: read

jobs:
test-website:
runs-on: ubuntu-latest
container: node
steps:
- name: Harden Runner
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
with:
egress-policy: audit

- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- run: npx envinfo
- name: Build and Deploy
env:
NODE_OPTIONS: --openssl-legacy-provider
working-directory: ./website
run: |
npm install
npx gatsby build --prefix-paths
16 changes: 8 additions & 8 deletions website/docs/special-topics/object-function-refs.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ This example code shows how to use the `FunctionReference` class.

### src/native-addon.h

[**native-addon.h**](https://github.com/nodejs/node-addon-examples/blob/main/src/4-references-and-handle-scope/function-reference-demo/src/native-addon.h)
[**native-addon.h**](https://github.com/nodejs/node-addon-examples/blob/main/src/4-references-and-handle-scope/function-reference-demo/node-addon-api/src/native-addon.h)

`embed:src/4-references-and-handle-scope/function-reference-demo/src/native-addon.h`
`embed:src/4-references-and-handle-scope/function-reference-demo/node-addon-api/src/native-addon.h`

The `NativeAddon` C++ class has two data members that are populated in the `NativeAddon` constructor:

Expand All @@ -51,9 +51,9 @@ The `NativeAddon` C++ class has two data members that are populated in the `Nati

### src/native-addon.cc

[**native-addon.cc**](https://github.com/nodejs/node-addon-examples/blob/main/src/4-references-and-handle-scope/function-reference-demo/src/native-addon.cc)
[**native-addon.cc**](https://github.com/nodejs/node-addon-examples/blob/main/src/4-references-and-handle-scope/function-reference-demo/node-addon-api/src/native-addon.cc)

`embed:src/4-references-and-handle-scope/function-reference-demo/src/native-addon.cc`
`embed:src/4-references-and-handle-scope/function-reference-demo/node-addon-api/src/native-addon.cc`

The `NativeAddon` constructor, which is called from JavaScript, takes two function arguments. The first argument is stored as a `Napi::FunctionReference` and the second is stored as a `Napi::Function`.

Expand All @@ -65,17 +65,17 @@ The `NativeAddon` class implements two methods which can be called from JavaScri

### src/binding.cc

[**binding.cc**](https://github.com/nodejs/node-addon-examples/blob/main/src/4-references-and-handle-scope/function-reference-demo/src/binding.cc)
[**binding.cc**](https://github.com/nodejs/node-addon-examples/blob/main/src/4-references-and-handle-scope/function-reference-demo/node-addon-api/src/binding.cc)

`embed:src/4-references-and-handle-scope/function-reference-demo/src/binding.cc`
`embed:src/4-references-and-handle-scope/function-reference-demo/node-addon-api/src/binding.cc`

This is a standard `binding.cc` file:

### index.js

[**index.js**](https://github.com/nodejs/node-addon-examples/blob/main/src/4-references-and-handle-scope/function-reference-demo/index.js)
[**index.js**](https://github.com/nodejs/node-addon-examples/blob/main/src/4-references-and-handle-scope/function-reference-demo/node-addon-api/index.js)

`embed:src/4-references-and-handle-scope/function-reference-demo/index.js`
`embed:src/4-references-and-handle-scope/function-reference-demo/node-addon-api/index.js`

This JavaScript code shows the use of the `NativeAddon` class. Note that the call to the native `tryCallByStoredFunction` method fails because the data member on which it relies is not valid.

Expand Down

0 comments on commit ed36ba2

Please sign in to comment.