I'm writing unit test for angular project.
Using
karma-typescript
.
And I got error:
Uncaught Error: Can't find entrypoint [D:/Projects/pmreport-phase-2/PMReport-Prj/PMReportClient/pmreport-web/ngapp/src/app/main/customer/detail/detail.component.spec.ts] (required by commonjs.js) at node_modules/karma-typescript/dist/client/commonjs.js:13:17
I'm trying research in gg, but I could not get any solution for this case.
My code:
karma config:
// Karma configuration
// Generated on Mon Feb 03 2020 17:18:41 GMT+0700 (Indochina Time)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
plugins : [
'karma-typescript',
'karma-chrome-launcher'
],
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['karma-typescript'],
// list of files / patterns to load in the browser
files: [
{pattern : 'src/**/*.spec.ts',included:true},
{pattern : 'src/**/*.spec.ts',included:false}
],
karmaTypescriptConfig : {
bundlerOptions: {
entrypoints: /\.spec\.ts$/
},
compilerOptions : {
module : "commonjs"
},
tsconfig : "./tsconfig.json",
},
// list of files / patterns to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
"**/*.spec.ts":"karma-typescript"
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress','karma-typescript'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
};
test file:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DetailCustomerComponent } from "./detail.component";
describe ('DetailCustomerComponent', () => {
let component: DetailCustomerComponent;
let fixture: ComponentFixture<DetailCustomerComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DetailCustomerComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DetailCustomerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Can you help me in this case ? I would be very grateful
Thanks for your time
Try the following config options: