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

separation of unit testing not working #294

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

Comments

Projects
None yet
2 participants
@jquerygeek
Copy link

jquerygeek commented Nov 22, 2016

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

This comment has been minimized.

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

chore: test framework improvements, remove tsconfig `exclude` clause
* 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 wardbell closed this Nov 30, 2016

wardbell added a commit that referenced this issue Nov 30, 2016

chore: test framework improvements, remove tsconfig `exclude` clause
* 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

chore(testing): karma config files support multiple builtPaths
* 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

chore(testing): karma config files support multiple builtPaths
* 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

chore(testing): karma config files support multiple builtPaths
* 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

chore(testing): karma config files support multiple builtPaths (#2917)
* 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 join this conversation on GitHub. Already have an account? Sign in to comment