node-red / node-red-node-test-helper

A test framework for Node-RED nodes
Apache License 2.0
57 stars 40 forks source link

upPkg new structure change crashing the Tester #49

Open biancode opened 3 years ago

biancode commented 3 years ago

upPkg.packageJson.name changed to upPkg.pkg.name

old:

    const upPkg = readPkgUp.sync();
    // case 1: we're in NR itself
    if (upPkg.packageJson.name === 'node-red') {

new:

    const upPkg = readPkgUp.sync();
    // case 1: we're in NR itself
    if (upPkg.pkg.name === 'node-red') {
knolleary commented 3 years ago

The latest version of read-pkg-up is 7.0.1, which is the version this module uses, returns packageJson, not pkg.

I seem to remember the module did use to return pkg - but that changed a while ago.

Checking the release history, read-pkg-up@5.0 and earlier would return pkg. In v6.0 they changed that to package, before changing it again to packageJson with the 7.0 release.

https://github.com/sindresorhus/read-pkg-up/releases

biancode commented 3 years ago

That is correct. Hm. The installed helper has 7.0.1 and that has a dependency to 5.2.0. The helper got the packages installed in its own node_modules, but if I use jest for testing it gets the old version by require() from an older package version, which is installed in the main node_modules from another package in that project that I tried to test. Interesting. It was a very fresh installation. I'll try to refresh the project to test it again.

biancode commented 3 years ago

maybe it is a Jest problem - very fresh install via npm after cache verify etc. - same problem

  ● Test suite failed to run

    TypeError: Cannot read property 'name' of undefined

      19 | var serverCmdNodes = [injectNode, functionNode, serverCmdNode]
      20 |
    > 21 | var helper = require('node-red-node-test-helper')
         |              ^
      22 | helper.init(require.resolve('node-red'))

      at findRuntimePath (node_modules/node-red-node-test-helper/index.js:40:27)
      at NodeTestHelper.init (node_modules/node-red-node-test-helper/index.js:146:38)
      at new NodeTestHelper (node_modules/node-red-node-test-helper/index.js:84:14)
      at Object.<anonymous> (node_modules/node-red-node-test-helper/index.js:352:18)
    const upPkg = readPkgUp.sync();
    // case 1: we're in NR itself
    if (upPkg.packageJson|(Cursor is here).name === 'node-red') {