Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

separation of unit testing not working #294

Closed
jquerygeek opened this issue Nov 22, 2016 · 1 comment
Closed

separation of unit testing not working #294

jquerygeek opened this issue Nov 22, 2016 · 1 comment

Comments

@jquerygeek
Copy link

Hello

I wanted to keep unit testing files in separate folder out of app/, I wanted to keep the outside of app/ as spec/unit/app.spec.js, but its giving error as


/angular2-project/spec/unit/app.component.spec.js".
    Chrome 54.0.2840 (Mac OS X 10.10.5): Executed 0 of 0 ERROR (0.006 secs / 0 secs)

Updated my karma.conf as
var testBase = 'spec/unit/';

can you advice please.

@wardbell
Copy link
Contributor

wardbell commented Nov 30, 2016

That was a problem! karma-test-shim couldn't handle more than one base path containing spec files.

I've updated karma-test-shim and karma.config accordingly. I made your use case work with the following changes

// karma-test-shim
...
// builtPaths: root paths for output ("built") files
// get from karma.config.js, then prefix with '/base/' (default is 'app/')
var builtPaths = (__karma__.config.builtPaths || ['app/'])
                 .map(function(p) { return '/base/'+p;});
...
// Is a "built" file if is JavaScript file in one of the "built" folders
function isBuiltFile(path) {
  return isJsFile(path) &&
         builtPaths.reduce(function(keep, bp) {
           return keep || (path.substr(0, bp.length) === bp);
         }, false);
}
...
// karma.config.js
  var appBase    = 'app/';       // transpiled app JS and map files
  var appSrcBase = 'app/';       // app source TS files
  var appAssets  = 'base/app/'; // component assets fetched by Angular's compiler

  var testingBase    = 'spec/unit/'; // transpiled test JS and map files
  var testingSrcBase = 'spec/unit/'; // test source TS files
...

    client: {
      builtPaths: [appSrcBase, testingBase], // add more spec base paths as needed
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
...

Attached the working project in the following zip
issue-294-example.zip

The fundamental changes to karma-test-shim and karma.config is now in master as v.0.2.18

wardbell added a commit that referenced this issue Nov 30, 2016
* remove `exclude` clause from `tsconfig.json`; it was just confusing people
* karma.config + karma-test-shim can handle multiple spec source paths (issue #294)
* cosmetic `app.component.spec.ts` changes
* cosmetic `karma.config.js` changes
wardbell added a commit that referenced this issue Nov 30, 2016
* remove `exclude` clause from `tsconfig.json`; it was just confusing people
* karma.config + karma-test-shim can handle multiple spec source paths (issue #294)
* cosmetic `app.component.spec.ts` changes
* cosmetic `karma.config.js` changes
wardbell added a commit to IdeaBlade/angular.io that referenced this issue Nov 30, 2016
* karma.config + karma-test-shim can handle multiple spec source paths;
  see quickstart issue: angular/quickstart#294
* cosmetic `karma.config.js` changes
wardbell added a commit to IdeaBlade/angular.io that referenced this issue Nov 30, 2016
* karma.config + karma-test-shim can handle multiple spec source paths;
  see quickstart issue: angular/quickstart#294
* cosmetic `karma.config.js` changes
wardbell added a commit to IdeaBlade/angular.io that referenced this issue Nov 30, 2016
* karma.config + karma-test-shim can handle multiple spec source paths;
  see quickstart issue: angular/quickstart#294
* cosmetic `karma.config.js` changes
wardbell added a commit to angular/angular.io that referenced this issue Nov 30, 2016
* karma.config + karma-test-shim can handle multiple spec source paths;
  see quickstart issue: angular/quickstart#294
* cosmetic `karma.config.js` changes
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants