define is not defined when trying to run my intern dojo tests

孤街浪徒 提交于 2020-01-14 05:40:29

问题


I've been trying to get intern to run with the intern-cucumber plugin for ages now. I am super confused about how to get my intern test even running. This is my file structure:

project

  • features
    • ar.feature
    • addition.feature
  • models
    • calculator.js
  • tests
    • addition.js
    • ar.js
  • intern.json
  • package.json

I want to create unit tests that run in the browser. The main issues arise with my arizona.js file, because it depends on several dojo libraries. Currently, my intern.json configuration file looks like:

{
  "loader": {
    "script": "dojo
  },
  "suites": "tests/**.js",
  "environments": [
    {
      "browserName": "chrome",
      "goog:chromeOptions": {
        "args": ["headless", "disable-gpu", "window-size=1024,768"]
      }
    }
  ],
  "browser": {
    "plugins": [
      "node_modules/intern/browser/intern.js",
      "node_modules/intern-cucumber/browser/plugin.js"
    ]
  },
  "node": {
    "plugins": "node_modules/intern-cucumber/plugin.js"
  }
}

my package.json looks like:

{
  "scripts": {
    "test": "intern"
  },
  "devDependencies": {
    "dojo": "^1.10.4",
    "intern": "^3.4.3",
    "intern-cucumber": "0.0.12"
  },
  "dependencies": {
    "dojo": "2.0.0"
  }
}

The dummy test that I'm running looks like:

define([
    'dojo/text!features/arizona.feature', 
    'path1/MockDeclaration', 
    'path2/A4Al2015'
], function (featureSrc, MockDeclaration, TaxFormClass) {

    const cucumber = intern.getInterface('cucumber');
    const assert = intern.getPlugin('chai').assert;

    cucumber.registerCucumber('tax form', featureSrc, function () {

        cucumber.Given('I have a tax form', function () {
            var theForm = new TaxFormClass();
        });

        cucumber.When('I check line one', function () {
            var theForm = new TaxFormClass();
            theForm.initTest();
            theForm.changeFieldValue(theForm.Line1, 0);


        })

        cucumber.Then('it should be true', function () {
            theForm.initTest();
            theForm.changeFieldValue(theForm.Line1, 0);
            assert.isTrue(theForm.Line2.disabled);

        })
    }

    )
}

)

And when I run my test, I run npm test in the windows powershell of my project. And I get this error:

ReferenceError: define is not defined
  at Object.<anonymous>  <node_modules\intern\lib\Suite.js:1:1>
  at Module._compile  <internal\modules\cjs\loader.js:778:30>
  at Object.Module._extensions..js  <internal\modules\cjs\loader.js:789:10>
  at Module.load  <internal\modules\cjs\loader.js:653:32>
  at tryModuleLoad  <internal\modules\cjs\loader.js:593:12>
  at Function.Module._load  <internal\modules\cjs\loader.js:585:3>
  at Module.require  <internal\modules\cjs\loader.js:692:17>
  at require  <internal\modules\cjs\helpers.js:25:18>
  at Object.<anonymous>  <node_modules\intern-cucumber\interface\cucumber.js:3:15>
  at Module._compile  <internal\modules\cjs\loader.js:778:30>
  at Object.Module._extensions..js  <internal\modules\cjs\loader.js:789:10>
  at Module.load  <internal\modules\cjs\loader.js:653:32>
  at tryModuleLoad  <internal\modules\cjs\loader.js:593:12>
  at Function.Module._load  <internal\modules\cjs\loader.js:585:3>
  at Module.require  <internal\modules\cjs\loader.js:692:17>
  at require  <internal\modules\cjs\helpers.js:25:18>
npm ERR! Test failed.  See above for more details.

When I was using Intern 4 with this same project, and my intern.json file had "functionalSuites" instead of suites, at least addition.js ran and the other file had windows and document undefined errors. I thought intern 4 may have been an issue so now im using v3.4.3 and changed it to unit tests instead of function tests and define doesn't even work.......Can't even comprehend how to fix this.

来源:https://stackoverflow.com/questions/59362329/define-is-not-defined-when-trying-to-run-my-intern-dojo-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!