Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Error/Bug
    4. iobroker/testing error

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    SOLVED iobroker/testing error

    This topic has been deleted. Only users with topic management privileges can see it.
    • 孙善明
      孙善明 last edited by 孙善明

      I wrote an adapter, but the following error occurred during automated testing, I need a little help

      travis-ci log
      github source

      "@iobroker/testing": "^1.2.5",
      
      The command "npm run test:package" exited with 0.
      1.37s$ npm run test:unit
      > iobroker.serve@0.0.1 test:unit /home/travis/build/smarthomefans/ioBroker.serve
      > mocha test/unit --exit
        Test the adapter (in a mocked environment)
          1) The adapter starts in normal mode
          2) The adapter starts in compact mode
        0 passing (78ms)
        2 failing
        1) Test the adapter (in a mocked environment)
             The adapter starts in normal mode:
           Error: Cannot find module '/home/travis/build/smarthomefans/iobroker.js-controller/lib/tools.js'
            at loadModuleInternal (node_modules/@iobroker/testing/build/tests/unit/harness/loader.js:166:26)
            at Module.fakeRequire [as require] (node_modules/@iobroker/testing/build/tests/unit/harness/loader.js:36:16)
            at require (internal/module.js:20:19)
            at startAdapter (main.js:36:58)
            at __dirname (main.js:151:2)
            at Object.<anonymous> (main.js:153:3)
            at Module.module._compile (node_modules/@iobroker/testing/build/tests/unit/harness/loader.js:158:24)
            at Object.replaceJsLoader (node_modules/@iobroker/testing/build/tests/unit/harness/loader.js:162:9)
            at require (internal/module.js:20:19)
            at loadModuleInternal (node_modules/@iobroker/testing/build/tests/unit/harness/loader.js:166:26)
            at Object.loadModuleInHarness (node_modules/@iobroker/testing/build/tests/unit/harness/loader.js:185:12)
            at Object.<anonymous> (node_modules/@iobroker/testing/build/tests/unit/harness/startMockAdapter.js:79:45)
            at next (native)
            at /home/travis/build/smarthomefans/ioBroker.serve/node_modules/@iobroker/testing/build/tests/unit/harness/startMockAdapter.js:8:71
            at __awaiter (node_modules/@iobroker/testing/build/tests/unit/harness/startMockAdapter.js:4:12)
            at Object.startMockAdapter (node_modules/@iobroker/testing/build/tests/unit/harness/startMockAdapter.js:36:12)
            at Context.<anonymous> (node_modules/@iobroker/testing/build/tests/unit/index.js:65:83)
            at next (native)
            at /home/travis/build/smarthomefans/ioBroker.serve/node_modules/@iobroker/testing/build/tests/unit/index.js:9:71
            at __awaiter (node_modules/@iobroker/testing/build/tests/unit/index.js:5:12)
            at Context.<anonymous> (node_modules/@iobroker/testing/build/tests/unit/index.js:61:20)
        2) Test the adapter (in a mocked environment)
             The adapter starts in compact mode:
           Error: Cannot find module '/home/travis/build/smarthomefans/iobroker.js-controller/lib/tools.js'
            at loadModuleInternal (node_modules/@iobroker/testing/build/tests/unit/harness/loader.js:166:26)
            at Module.fakeRequire [as require] (node_modules/@iobroker/testing/build/tests/unit/harness/loader.js:36:16)
            at require (internal/module.js:20:19)
            at startAdapter (main.js:36:58)
            at Object.<anonymous> (node_modules/@iobroker/testing/build/tests/unit/harness/startMockAdapter.js:89:17)
            at next (native)
            at /home/travis/build/smarthomefans/ioBroker.serve/node_modules/@iobroker/testing/build/tests/unit/harness/startMockAdapter.js:8:71
            at __awaiter (node_modules/@iobroker/testing/build/tests/unit/harness/startMockAdapter.js:4:12)
            at Object.startMockAdapter (node_modules/@iobroker/testing/build/tests/unit/harness/startMockAdapter.js:36:12)
            at Context.<anonymous> (node_modules/@iobroker/testing/build/tests/unit/index.js:80:105)
            at next (native)
            at /home/travis/build/smarthomefans/ioBroker.serve/node_modules/@iobroker/testing/build/tests/unit/index.js:9:71
            at __awaiter (node_modules/@iobroker/testing/build/tests/unit/index.js:5:12)
            at Context.<anonymous> (node_modules/@iobroker/testing/build/tests/unit/index.js:76:24)
      npm ERR! Linux 4.4.0-101-generic
      npm ERR! argv "/home/travis/.nvm/versions/node/v6.17.1/bin/node" "/home/travis/.nvm/versions/node/v6.17.1/bin/npm" "run" "test:unit"
      npm ERR! node v6.17.1
      npm ERR! npm  v3.10.10
      npm ERR! code ELIFECYCLE
      npm ERR! iobroker.serve@0.0.1 test:unit: `mocha test/unit --exit`
      npm ERR! Exit status 2
      npm ERR! 
      npm ERR! Failed at the iobroker.serve@0.0.1 test:unit script 'mocha test/unit --exit'.
      npm ERR! Make sure you have the latest version of node.js and npm installed.
      npm ERR! If you do, this is most likely a problem with the iobroker.serve package,
      npm ERR! not with npm itself.
      npm ERR! Tell the author that this fails on your system:
      npm ERR!     mocha test/unit --exit
      npm ERR! You can get information on how to open an issue for this project with:
      npm ERR!     npm bugs iobroker.serve
      npm ERR! Or if that isn't available, you can get their info via:
      npm ERR!     npm owner ls iobroker.serve
      npm ERR! There is likely additional logging output above.
      npm ERR! Please include the following file with any support request:
      npm ERR!     /home/travis/build/smarthomefans/ioBroker.serve/npm-debug.log
      The command "npm run test:unit" exited with 1.
      

      @Bluefox

      1 Reply Last reply Reply Quote 0
      • AlCalzone
        AlCalzone Developer @孙善明 last edited by AlCalzone

        @孙善明 If you are relying on files from js-controller (like tools.js), you need to mock the methods in order to use them in unit tests. Remember, those don't have a real js-controller in the background.
        This is documented here: https://github.com/ioBroker/testing#adapter-startup-unit-test (in the middle of the code block). You would have to mock getDefaultDataDir, like this:

        "{CONTROLLER_DIR}/lib/tools.js": {
            getDefaultDataDir() { return "../../iobroker-data"; }
        },
        

        (I'm not 100% sure about the actual return value).

        1 Reply Last reply Reply Quote 0
        • 孙善明
          孙善明 last edited by

          I found the problem here.

           * @param {Partial<ioBroker.AdapterOptions>} [options]
           */
          function startAdapter(options) {
          	// Create the adapter and define its methods
          	dataDir = path.normalize(path.join(utils.controllerDir, require(path.join(utils.controllerDir, 'lib', 'tools.js')).getDefaultDataDir()));
          
          	return adapter = utils.adapter(Object.assign({}, options, {
          		name: "serve",
          
          		// The ready callback is called when databases are connected and adapter received configuration.
          		// start here!
          		ready: main, // Main method defined below for readability
          
          		// is called when adapter shuts down - callback has to be called under any circumstances!
          		unload: (callback) => {
          			try {
          				adapter.log.info("cleaned everything up...");
          				callback();
          			} catch (e) {
          				callback();
          			}
          		},
          
          1 Reply Last reply Reply Quote 0
          • 孙善明
            孙善明 last edited by

            solved

            dataDir = path.normalize(utils.controllerDir + '/iobroker-data/')
            
            AlCalzone 1 Reply Last reply Reply Quote 0
            • AlCalzone
              AlCalzone Developer @孙善明 last edited by AlCalzone

              @孙善明 If you are relying on files from js-controller (like tools.js), you need to mock the methods in order to use them in unit tests. Remember, those don't have a real js-controller in the background.
              This is documented here: https://github.com/ioBroker/testing#adapter-startup-unit-test (in the middle of the code block). You would have to mock getDefaultDataDir, like this:

              "{CONTROLLER_DIR}/lib/tools.js": {
                  getDefaultDataDir() { return "../../iobroker-data"; }
              },
              

              (I'm not 100% sure about the actual return value).

              1 Reply Last reply Reply Quote 0
              • First post
                Last post

              Support us

              ioBroker
              Community Adapters
              Donate

              475
              Online

              31.8k
              Users

              80.0k
              Topics

              1.3m
              Posts

              test
              2
              4
              334
              Loading More Posts
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes
              Reply
              • Reply as topic
              Log in to reply
              Community
              Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
              The ioBroker Community 2014-2023
              logo