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

Fix/prebuildify path lookup #452

Merged
merged 4 commits into from
Jul 6, 2023

Conversation

YOU54F
Copy link
Member

@YOU54F YOU54F commented Jul 6, 2023

Right two issues

  1. The path lookup is looking at the root of the project folder, and not in the node_modules directory

  2. env var LOG_LEVEL doesn't affect logging of the FFI native module, as that uses DEFAULT_LOG_LEVEL or the user provided instead ofcurrentLogLevel which was modified to take account of the env var LOG_LEVEL

simple test of the standalone and ffi

const pact = require('@pact-foundation/pact-core')
pact.createServer()
 .delete()
 .then(function() {
  console.log('pact ruby standalone server created and deleted')
 });

const consumerPact = pact.makeConsumerPact(
    'foo-consumer',
    'bar-provider',
    4 ,// v3 spec,
    'TRACE'
  );
const interaction = consumerPact.newInteraction('some description');

interaction.uponReceiving('a request to get a dog');
interaction.given('fido exists');
interaction.withRequest('GET', '/dogs/1234');
interaction.withResponseBody(
JSON.stringify({
    name: 'fido',
    age: 23,
    alive: true,
}),
'application/json'
);
interaction.withStatus(200);

port = consumerPact.createMockServer('127.0.0.1');
// port = consumerPact.createMockServer('localhost'); // Error in native callback - JSON.parse(ffi.pactffiMockServerMismatches(port)) 
console.log(port)
consumerPact.mockServerMatchedSuccessfully(port)
const mismatches = consumerPact.mockServerMismatches(port);
console.log(mismatches)

npm install @pact-foundation/pact-core

LOG_LEVEL=debug node test.js

You can see the lookup path is /Users/yousaf.nabi/dev/fooscratch/prebuilds/darwin-arm64 but it should be ` /Users/yousaf.nabi/dev/fooscratch/node_modules/@pact-foundation/pact-core/prebuilds/darwin-arm64

[11:46:08.471] DEBUG (10503): pact-core@13.14.0: Attempting to find pact native module : loading native module from: 

 - /Users/yousaf.nabi/dev/fooscratch/prebuilds/darwin-arm64 
   source: pact-js-core binding lookup 

 - You can override via PACT_PREBUILD_LOCATION

[11:46:08.473] DEBUG (10503): pact-core@13.14.0: Supported platforms are: 
 - darwin-arm64
 - darwin-x64
 - linux-arm64
 - linux-x64
 - win32-x64
We detected your platform as: 

 - darwin-arm64

[11:46:08.474] ERROR (10503): pact-core@13.14.0: Failed to initialise native module for darwin-arm64: Error: No native build was found for platform=darwin arch=arm64 runtime=node abi=93 uv=1 armv=8 libc=glibc node=16.20.0
    loaded from: /Users/yousaf.nabi/dev/fooscratch

[11:46:08.474] DEBUG (10503): pact-core@13.14.0: {supportedPlatformsMessage}
We detected your platform as: 

 - darwin-arm64


      We looked for a supported build in this location /Users/yousaf.nabi/dev/fooscratch/prebuilds/darwin-arm64

      Tip: check there is a prebuild for darwin-arm64 

      check the prebuild exists at the path: /Users/yousaf.nabi/dev/fooscratch/prebuilds/darwin-arm64

      Wrong Path?: set the load path with PACT_PREBUILD_LOCATION ensuring that $PACT_NODE_NAPI_LOCATION/prebuilds/darwin-arm64 exists

      - Note: You dont need to include the prebuilds/darwin-arm64 part of the path, just the parent directory

      - Let us know: We can add more supported path lookups easily, chat to us on slack or raise an issue on github
[11:46:08.474] INFO (10503): pact-core@13.14.0: Removing all Pact servers.
/Users/yousaf.nabi/dev/fooscratch/node_modules/@pact-foundation/pact-core/src/ffi/index.js:94
        throw new Error(`Failed to load native module, try setting LOG_LEVEL=debug for more info \n. ${error}`);
        ^

Error: Failed to load native module, try setting LOG_LEVEL=debug for more info 
. TypeError: Cannot read properties of undefined (reading 'pactffiInitWithLogLevel')

LOG_LEVEL=debug PACT_PREBUILD_LOCATION=$PWD/node_modules/@pact-foundation/pact-core node test.js

2023-07-06T10:41:20.317521Z DEBUG ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x16f8e5958 tls=false}: pact_mock_server::mock_server: Started mock server on 127.0.0.1:51574
2023-07-06T10:41:20.317539Z TRACE ThreadId(01) pactffi_create_mock_server_for_pact{pact=PactHandle { pact_ref: 1 } addr_str=0x16f8e5958 tls=false}: pact_ffi::mock_server::handles: with_pact after - ref = 1, inner = RefCell { value: PactHandleInner { pact: V4Pact { consumer: Consumer { name: "foo-consumer" }, provider: Provider { name: "bar-provider" }, interactions: [SynchronousHttp { id: None, key: None, description: "a request to get a dog", provider_states: [ProviderState { name: "fido exists", params: {} }], request: HttpRequest { method: "GET", path: "/dogs/1234", query: None, headers: None, body: Missing, matching_rules: MatchingRules { rules: {PATH: MatchingRuleCategory { name: PATH, rules: {} }} }, generators: Generators { categories: {} } }, response: HttpResponse { status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(b"{\"age\":23,\"alive\":true,\"name\":\"fido\"}", Some(ContentType { main_type: "application", sub_type: "json", attributes: {}, suffix: None }), None), matching_rules: MatchingRules { rules: {BODY: MatchingRuleCategory { name: BODY, rules: {} }} }, generators: Generators { categories: {} } }, comments: {}, pending: false, plugin_config: {}, interaction_markup: InteractionMarkup { markup: "", markup_type: "" }, transport: None }], metadata: {"pactRust": Object {"ffi": String("0.4.0")}}, plugin_data: [] }, mock_server_started: true, specification_version: V3 } }
51574
[
  {
    method: 'GET',
    path: '/dogs/1234',
    request: { method: 'GET', path: '/dogs/1234' },
    type: 'missing-request'
  }
]
[11:41:20.320] INFO (10256): pact-core@13.14.0: Deleting Pact Server with options: 
{"dir":"/Users/yousaf.nabi/dev/fooscratch","pactFileWriteMode":"overwrite","ssl":false,"cors":false,"host":"localhost"}
pact ruby standalone server created and deleted

@YOU54F
Copy link
Member Author

YOU54F commented Jul 6, 2023

hmm there should a third commit fixing the linting 🤔

@YOU54F
Copy link
Member Author

YOU54F commented Jul 6, 2023

hmm there should a third commit fixing the linting 🤔

ahh synced now

@YOU54F YOU54F merged commit 643f075 into pact-foundation:master Jul 6, 2023
31 checks passed
@YOU54F YOU54F deleted the fix/prebuildify_path_lookup branch June 26, 2024 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants