Ivaro18 Ivaro18 - 8 days ago 6
Node.js Question

Karma -- [preprocessor.rollup]: Could not resolve '../../services/service.ts'




I'm having a testsuite which I'm now trying to test via CI. (Bamboo)

The problem is that this is fully functional on my local system, but wen I deploy it to the Bamboo server (which I cannot configure myself) the call
npm --harmony test
(
--harmony
to use
const
while
use strict
) fails.

Next, it returns the following errormessage

07-Oct-2016 16:37:03 07 10 2016 16:37:03.315:ERROR [preprocessor.rollup]: Could not resolve '../../services/apicaller.service' from /opt/bamboo-home/xml-data/build-dir/MCAE-MANCAVE-JOB1/src/pages/events/events.component.ts
07-Oct-2016 16:37:03 at /opt/bamboo-home/xml-data/build-dir/MCAE-MANCAVE-JOB1/config/karma-shim.ts
07-Oct-2016 16:37:03 Error: Could not resolve '../../services/apicaller.service' from /opt/bamboo-home/xml-data/build-dir/MCAE-MANCAVE-JOB1/src/pages/events/events.component.ts
07-Oct-2016 16:37:03 at Error (native)
07-Oct-2016 16:37:03 at /opt/bamboo-home/xml-data/build-dir/MCAE-MANCAVE-JOB1/node_modules/rollup-plugin-node-resolve/dist/rollup-plugin-node-resolve.cjs.js:78:21
07-Oct-2016 16:37:03 at /opt/bamboo-home/xml-data/build-dir/MCAE-MANCAVE-JOB1/node_modules/browser-resolve/index.js:265:24
07-Oct-2016 16:37:03 at /opt/bamboo-home/xml-data/build-dir/MCAE-MANCAVE-JOB1/node_modules/resolve/lib/async.js:55:18
07-Oct-2016 16:37:03 at load (/opt/bamboo-home/xml-data/build-dir/MCAE-MANCAVE-JOB1/node_modules/resolve/lib/async.js:69:43)
07-Oct-2016 16:37:03 at onex (/opt/bamboo-home/xml-data/build-dir/MCAE-MANCAVE-JOB1/node_modules/resolve/lib/async.js:92:31)
07-Oct-2016 16:37:03 at /opt/bamboo-home/xml-data/build-dir/MCAE-MANCAVE-JOB1/node_modules/resolve/lib/async.js:22:47


where
../../services/apicaller.service
is an import statement in
src/pages/events/events.component





Project structure (minified to match errormessage's scope)

src
|
--config
| |
| --karma.conf.js
| --karma-shim.ts
| --protractor.conf.js
| --rollup.config.js
|
--pages
| |
| --events
| |
| --events.component.ts
|
--services
|
--APICaller.service.ts





Karma.conf.js:

'use strict';

const path = require('path');
const ts = require('rollup-plugin-typescript');
const buble = require('rollup-plugin-buble');
const nodeResolve = require('rollup-plugin-node-resolve');
const angular = require('rollup-plugin-angular');
const commonjs = require('rollup-plugin-commonjs');
const alias = require('rollup-plugin-alias');

module.exports = function karmaConfig(config) {
var configuration = {
// base path that will be used to resolve all patterns (e.g. files, exclude)
basePath: '../',
frameworks: ['jasmine'],
plugins: [
require('karma-jasmine'),
require('karma-phantomjs-launcher'),
require('karma-rollup-plugin')
],
reporters: [
// // Reference: https://github.com/mlex/karma-spec-reporter
// // Set reporter to print detailed results to console
// 'spec',
// // Reference: https://github.com/karma-runner/karma-coverage
// // Output code coverage files
// 'coverage'
'progress'
],
// list of files / patterns to load in the browser we are building
// the config environment in ./karma-shim.js
files: [
'config/karma-shim.ts'
],
preprocessors: {
'config/karma-shim.ts': ['rollup']
},
rollupPreprocessor: {
context: 'this',
plugins: [
angular({
exclude: 'node_modules/**'
}),
ts({
typescript: require('../node_modules/typescript')
}),
alias({
'@angular/core/testing': path.resolve(__dirname, '../node_modules/@angular/core/testing/index.js'),
'@angular/platform-browser-dynamic/testing': path.resolve(__dirname, '../node_modules/@angular/platform-browser-dynamic/testing/index.js'),
'@angular/compiler/testing': path.resolve(__dirname, '../node_modules/@angular/compiler/testing/index.js'),
'@angular/platform-browser/testing': path.resolve(__dirname, '../node_modules/@angular/platform-browser/testing/index.js')
}),
commonjs(),
nodeResolve({ jsnext: true, main: true, browser: true }),
buble()
]
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS'],
// Continuous Integration mode if true, Karma captures browsers, runs the tests and exits
singleRun: true
};

// if(process.env.GITLAB_CI){
// //configuration.browsers = ['Chrome_travis_ci'];
// }

config.set(configuration);
};





Karma-shim.ts

declare var __karma__: any;

__karma__.loaded = () => { };

import 'core-js/client/shim';
import 'reflect-metadata';
import 'zone.js/dist/zone';
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/proxy';
import 'zone.js/dist/jasmine-patch';

import 'rxjs/Rx';

import { TestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';

TestBed.initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);

import '../src/pages/home/home.spec';
import '../src/pages/events/events.spec';
import '../src/pages/event-detail/event-detail.spec';

__karma__.start();





rollup.config.js

const rollupConfig = require('../node_modules/@ionic/app-scripts/config/rollup.config');
const replace = require('rollup-plugin-replace');

console.log('Editing default ionic configuration');

const nodeEnv = JSON.stringify(process.env.NODE_ENV) || 'development';
const apiUrl = JSON.stringify(process.env.API_URL) || '';
const platform = JSON.stringify(process.env.PLATFORM) || 'android';

rollupConfig.plugins.push(replace({
'process.env.NODE_ENV': nodeEnv,
'process.env.API_URL': apiUrl,
'process.env.PLATFORM': platform
}));

module.exports = rollupConfig;

Answer

I figured that Bamboo is case-sensitive. And since my APICaller doesn't follow the angular's kebab-case, Bamboo couldn't find the path.

Class was APICaller.service.ts and import was {..} from 'apicaller.service. Change to {..} from 'APICaller.service made it work

Comments