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

Unit test helpers not loaded correctly when using SystemJS #648

Closed
simonfox opened this issue Jun 14, 2017 · 4 comments · Fixed by #651
Closed

Unit test helpers not loaded correctly when using SystemJS #648

simonfox opened this issue Jun 14, 2017 · 4 comments · Fixed by #651
Labels

Comments

@simonfox
Copy link
Contributor

simonfox commented Jun 14, 2017

@JeroenVinke I have found a case where au test will break when using SystemJS......but I also have the solution, just wanted to run past you...

If you define a module in the test folder (for example a mock) and then import that into your test, it does not get loaded (404's). e.g. add /test/unit/helper.js then in app.spec.js add import {MyMock} from './helper';. This is because it is not defined in the bundle, and /base/test/unit/helper does not resolve to anything.

All that is needed is a SystemJS package definition added to config that sets the defaultExtension property:

SystemJS.config({
  "packages": {
    "base/test": {
      "defaultExtension": "js"
    }
  }
});

Currently aurelia-karma.js has normalizePath and patchRequireJS which aren't actually used by SystemJS and this file seems like the appropriate place to add the required SystemJS config. Was thinking I could just add aurelia-karma.system.js and aurelia-karma.require.js as I did with index.html so that au new adds the appropriate setup.....thoughts?

@JeroenVinke
Copy link
Collaborator

I wonder why this isn't needed for the skeletons. Is it because of defaultJSExtensions: true, ?

@simonfox
Copy link
Contributor Author

simonfox commented Jun 14, 2017

Yes....however defaultJSExtensions is removed in SystemJS 0.20.0.

However we need the ability to define by package because the amodoro bundle contains module names that do not include the extension - everything in /src. We still want src imports in test modules to load from bundles i.e. import {App} from '../../src/app so we dont want defaultExtension to apply to that path.

Make sense?

@JeroenVinke
Copy link
Collaborator

It does. Could you put together a PR?

@simonfox
Copy link
Contributor Author

simonfox commented Jun 14, 2017 via email

simonfox added a commit to simonfox/cli that referenced this issue Jun 14, 2017
An import of a unit test _helper_ module from within a spec was failing (e.g. a module that defines a mock). This was due to the import statement normalization result not having a .js extension. This change splits aurelia-karma into two loader specific implementations, with the SystemJS version adding a package configuration for the base/test path that sets `defaultExtension` to js. `au new` adds an implementation based on the selected loader.

closes aurelia#648
simonfox added a commit to simonfox/cli that referenced this issue Jun 14, 2017
An import of a unit test _helper_ module from within a spec was failing (e.g. a module that defines a mock). This was due to the import statement normalization result not having a .js extension. This change splits aurelia-karma into two loader specific implementations, with the SystemJS version adding a package configuration for the base/test path that sets `defaultExtension` to js. `au new` adds an implementation based on the selected loader.

closes aurelia#648
simonfox added a commit to simonfox/cli that referenced this issue Jun 15, 2017
An import of a unit test _helper_ module from within a spec was failing (e.g. a module that defines a mock). This was due to the import statement normalization result not having a .js extension. This change splits aurelia-karma into two loader specific implementations, with the SystemJS version adding a package configuration for the base/test path that sets `defaultExtension` to js. `au new` adds an implementation based on the selected loader.

closes aurelia#648
JeroenVinke added a commit that referenced this issue Jun 27, 2017
fix(systemjs-loader): systemjs config for karma test runner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants