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

test(stark-all): simplify karma configuration in stark-* packages + showcase #1474

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/karma.conf.ci.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const helpers = require("./stark-testing/helpers");

/**
* Load karma config from Stark
*/
const defaultKarmaCIConfig = require("./stark-testing/karma.conf.ci.js").rawKarmaConfig;
const { karmaTypescriptBundlerAlias, karmaTypescriptFiles } = require("./karma.conf");

// start customizing the KarmaCI configuration from stark-testing
const starkPackagesSpecificConfiguration = {
...defaultKarmaCIConfig,
// change the path of the report so that Coveralls takes the right path to the source files
coverageIstanbulReporter: { ...defaultKarmaCIConfig.coverageIstanbulReporter, dir: helpers.root("reports/coverage/packages") },
// add missing files due to "@nationalbankbelgium/stark-ui" imports used in mock files of the testing sub-package
files: [...defaultKarmaCIConfig.files, ...karmaTypescriptFiles],
karmaTypescriptConfig: {
...defaultKarmaCIConfig.karmaTypescriptConfig,
bundlerOptions: {
...defaultKarmaCIConfig.karmaTypescriptConfig.bundlerOptions,
// change the module resolution for the KarmaTypescript bundler
resolve: {
alias: karmaTypescriptBundlerAlias
},
// Overwrite the karmaTypescriptConfig to pass the correct preset to karma-typescript-es6-transform
transforms: [
require(helpers.root("../stark-testing/node_modules/karma-typescript-angular2-transform")),
require(helpers.root("../stark-testing/node_modules/karma-typescript-es6-transform"))({
presets: [helpers.root("../stark-testing/node_modules/babel-preset-env")] // add preset in a way that the package can find it
})
]
}
}
};

// export the configuration function that karma expects and simply return the stark configuration
module.exports = {
default: function(config) {
return config.set(starkPackagesSpecificConfiguration);
},
rawKarmaConfig: starkPackagesSpecificConfiguration
};
79 changes: 79 additions & 0 deletions packages/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const helpers = require("./stark-testing/helpers");

/**
* Load karma config from Stark
*/
const defaultKarmaConfig = require("./stark-testing/karma.conf.js").rawKarmaConfig;

// entry files of the "@nationalbankbelgium/stark-ui" module imported in mock files
const karmaTypescriptFiles = [{ pattern: helpers.root("public_api.ts") }, { pattern: helpers.root("testing/**/*.ts") }];

const karmaTypescriptBundlerAlias = {
// adapt the resolution of the stark-core module to the UMD module
"@nationalbankbelgium/stark-core": "../../dist/packages/stark-core/bundles/stark-core.umd.js",
"@nationalbankbelgium/stark-core/testing": "../../dist/packages/stark-core/bundles/stark-core-testing.umd.js",
// adapt the resolution of the 3rd party modules used in stark-core
"@angularclass/hmr": "../stark-core/node_modules/@angularclass/hmr/dist/index.js",
"@ng-idle/core": "../stark-core/node_modules/@ng-idle/core/bundles/core.umd.js",
"@ng-idle/keepalive": "../stark-core/node_modules/@ng-idle/keepalive/bundles/keepalive.umd.js",
"@ngrx/store": "../stark-core/node_modules/@ngrx/store/bundles/store.umd.js",
"@ngrx/effects": "../stark-core/node_modules/@ngrx/effects/bundles/effects.umd.js",
"@ngrx/effects/testing": "../stark-core/node_modules/@ngrx/effects/bundles/effects-testing.umd.js",
"@ngx-translate/core": "../stark-core/node_modules/@ngx-translate/core/bundles/ngx-translate-core.umd.js",
"@uirouter/angular": "../stark-core/node_modules/@uirouter/angular/_bundles/ui-router-ng2.js",
"@uirouter/core": "../stark-core/node_modules/@uirouter/core/lib/index.js",
"@uirouter/rx": "../stark-core/node_modules/@uirouter/rx/lib/index.js",
cerialize: "../stark-core/node_modules/cerialize/index.js",
"class-validator": "../stark-core/node_modules/class-validator/index.js",
"deep-freeze-strict": "../stark-core/node_modules/deep-freeze-strict/index.js",
ibantools: "../stark-core/node_modules/ibantools/build/ibantools.js",
"lodash-es": "../stark-core/node_modules/lodash-es/lodash.js",
"lodash-es/cloneDeep": "../stark-core/node_modules/lodash-es/cloneDeep.js",
"lodash-es/find": "../stark-core/node_modules/lodash-es/find.js",
"lodash-es/findIndex": "../stark-core/node_modules/lodash-es/findIndex.js",
"lodash-es/floor": "../stark-core/node_modules/lodash-es/floor.js",
"lodash-es/get": "../stark-core/node_modules/lodash-es/get.js",
"lodash-es/isEmpty": "../stark-core/node_modules/lodash-es/isEmpty.js",
"lodash-es/isEqual": "../stark-core/node_modules/lodash-es/isEqual.js",
"lodash-es/merge": "../stark-core/node_modules/lodash-es/merge.js",
"lodash-es/noop": "../stark-core/node_modules/lodash-es/noop.js",
"lodash-es/sortBy": "../stark-core/node_modules/lodash-es/sortBy.js",
"lodash-es/reduce": "../stark-core/node_modules/lodash-es/reduce.js",
"lodash-es/startCase": "../stark-core/node_modules/lodash-es/startCase.js",
"lodash-es/uniqueId": "../stark-core/node_modules/lodash-es/uniqueId.js",
moment: "../stark-core/node_modules/moment/moment.js"
};

// start customizing the KarmaCI configuration from stark-testing
const starkPackagesSpecificConfiguration = {
...defaultKarmaConfig,
// add missing files due to "@nationalbankbelgium/stark-*" imports used in mock files of the testing sub-package
files: [...defaultKarmaConfig.files, ...karmaTypescriptFiles],
karmaTypescriptConfig: {
...defaultKarmaConfig.karmaTypescriptConfig,
bundlerOptions: {
...defaultKarmaConfig.karmaTypescriptConfig.bundlerOptions,
// change the module resolution for the KarmaTypescript bundler
resolve: {
alias: karmaTypescriptBundlerAlias
},
// Overwrite the karmaTypescriptConfig to pass the correct preset to karma-typescript-es6-transform
transforms: [
require(helpers.root("../stark-testing/node_modules/karma-typescript-angular2-transform")),
require(helpers.root("../stark-testing/node_modules/karma-typescript-es6-transform"))({
presets: [helpers.root("../stark-testing/node_modules/babel-preset-env")] // add preset in a way that the package can find it
})
]
}
}
};

// export the configuration function that karma expects and simply return the stark configuration
module.exports = {
default: function(config) {
return config.set(starkPackagesSpecificConfiguration);
},
karmaTypescriptBundlerAlias,
karmaTypescriptFiles,
rawKarmaConfig: starkPackagesSpecificConfiguration
};
30 changes: 3 additions & 27 deletions packages/stark-core/karma.conf.ci.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,11 @@
const helpers = require("../stark-testing/helpers");

/**
* Load karma config from Stark
* Load packages karma config
*/
const defaultKarmaCIConfig = require("../stark-testing/karma.conf.ci.js").rawKarmaConfig;
const karmaTypescriptFiles = require("./karma.conf").karmaTypescriptFiles;

// start customizing the KarmaCI configuration from stark-testing
const starkCoreSpecificConfiguration = Object.assign({}, defaultKarmaCIConfig, {
// change the path of the report so that Coveralls takes the right path to the source files
coverageIstanbulReporter: Object.assign(defaultKarmaCIConfig.coverageIstanbulReporter, {
dir: helpers.root("reports/coverage/packages")
}),
// add missing files due to "@nationalbankbelgium/stark-core" imports used in mock files of the testing sub-package
files: [...defaultKarmaCIConfig.files, ...karmaTypescriptFiles],
// Overwrite the karmaTypescriptConfig to pass the correct preset to karma-typescript-es6-transform
karmaTypescriptConfig: {
...defaultKarmaCIConfig.karmaTypescriptConfig,
bundlerOptions: {
...defaultKarmaCIConfig.karmaTypescriptConfig.bundlerOptions,
transforms: [
require("../stark-testing/node_modules/karma-typescript-angular2-transform"),
require("../stark-testing/node_modules/karma-typescript-es6-transform")({
presets: [helpers.root("../stark-testing/node_modules/babel-preset-env")] // add preset in a way that the package can find it
})
]
}
}
});
const rawKarmaConfig = require("../karma.conf.ci.js").rawKarmaConfig;

// export the configuration function that karma expects and simply return the stark configuration
module.exports = config => {
return config.set(starkCoreSpecificConfiguration);
return config.set(rawKarmaConfig);
};
33 changes: 4 additions & 29 deletions packages/stark-core/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
const helpers = require("../stark-testing/helpers");

/**
* Load karma config from Stark
* Load packages karma config
*/
const defaultKarmaConfig = require("../stark-testing/karma.conf.js").rawKarmaConfig;

// entry files of the "@nationalbankbelgium/stark-core" module imported in mock files
const karmaTypescriptFiles = [{ pattern: helpers.root("public_api.ts") }, { pattern: helpers.root("testing/**/*.ts") }];

// start customizing the Karma configuration from stark-testing
const starkCoreSpecificConfiguration = Object.assign({}, defaultKarmaConfig, {
// add missing files due to "@nationalbankbelgium/stark-core" imports used in mock files of the testing sub-package
files: [...defaultKarmaConfig.files, ...karmaTypescriptFiles],
// Overwrite the karmaTypescriptConfig to pass the correct preset to karma-typescript-es6-transform
karmaTypescriptConfig: {
...defaultKarmaConfig.karmaTypescriptConfig,
bundlerOptions: {
...defaultKarmaConfig.karmaTypescriptConfig.bundlerOptions,
transforms: [
require("../stark-testing/node_modules/karma-typescript-angular2-transform"),
require("../stark-testing/node_modules/karma-typescript-es6-transform")({
presets: [helpers.root("../stark-testing/node_modules/babel-preset-env")] // add preset in a way that the package can find it
})
]
}
}
});
const rawKarmaConfig = require("../karma.conf.js").rawKarmaConfig;

// export the configuration function that karma expects and simply return the stark configuration
module.exports = {
default: function(config) {
return config.set(starkCoreSpecificConfiguration);
},
karmaTypescriptFiles: karmaTypescriptFiles
module.exports = config => {
return config.set(rawKarmaConfig);
};
32 changes: 3 additions & 29 deletions packages/stark-rbac/karma.conf.ci.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,11 @@
const helpers = require("../stark-testing/helpers");

/**
* Load karma config from Stark
* Load packages karma config
*/
const defaultKarmaCIConfig = require("../stark-testing/karma.conf.ci.js").rawKarmaConfig;
const karmaTypescriptBundlerAliasResolution = require("./karma.conf").karmaTypescriptBundlerAliasResolution;
const karmaTypescriptFiles = require("./karma.conf").karmaTypescriptFiles;

// start customizing the KarmaCI configuration from stark-testing
const starkRBACSpecificConfiguration = {
...defaultKarmaCIConfig,
// change the path of the report so that Coveralls takes the right path to the source files
coverageIstanbulReporter: { ...defaultKarmaCIConfig.coverageIstanbulReporter, dir: helpers.root("reports/coverage/packages") },
// add missing files due to "@nationalbankbelgium/stark-rbac" imports used in mock files of the testing sub-package
files: [...defaultKarmaCIConfig.files, ...karmaTypescriptFiles],
karmaTypescriptConfig: {
...defaultKarmaCIConfig.karmaTypescriptConfig,
bundlerOptions: {
...defaultKarmaCIConfig.karmaTypescriptConfig.bundlerOptions,
// change the module resolution for the KarmaTypescript bundler
...karmaTypescriptBundlerAliasResolution,
// Overwrite the karmaTypescriptConfig to pass the correct preset to karma-typescript-es6-transform
transforms: [
require("../stark-testing/node_modules/karma-typescript-angular2-transform"),
require("../stark-testing/node_modules/karma-typescript-es6-transform")({
presets: [helpers.root("../stark-testing/node_modules/babel-preset-env")] // add preset in a way that the package can find it
})
]
}
}
};
const rawKarmaConfig = require("../karma.conf.ci.js").rawKarmaConfig;

// export the configuration function that karma expects and simply return the stark configuration
module.exports = config => {
return config.set(starkRBACSpecificConfiguration);
return config.set(rawKarmaConfig);
};
68 changes: 4 additions & 64 deletions packages/stark-rbac/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,11 @@
const helpers = require("../stark-testing/helpers");

/**
* Load karma config from Stark
* Load packages karma config
*/
const defaultKarmaConfig = require("../stark-testing/karma.conf.js").rawKarmaConfig;

// entry files of the "@nationalbankbelgium/stark-rbac" module imported in mock files
const karmaTypescriptFiles = [{ pattern: helpers.root("public_api.ts") }, { pattern: helpers.root("testing/**/*.ts") }];

const karmaTypescriptBundlerAliasResolution = {
resolve: {
alias: {
// adapt the resolution of the stark-core module to the UMD module
"@nationalbankbelgium/stark-core": "../../dist/packages/stark-core/bundles/stark-core.umd.js",
"@nationalbankbelgium/stark-core/testing": "../../dist/packages/stark-core/bundles/stark-core-testing.umd.js",
// adapt the resolution of the 3rd party modules used in stark-core
"@angularclass/hmr": "../stark-core/node_modules/@angularclass/hmr/dist/index.js",
"@ng-idle/core": "../stark-core/node_modules/@ng-idle/core/bundles/core.umd.js",
"@ng-idle/keepalive": "../stark-core/node_modules/@ng-idle/keepalive/bundles/keepalive.umd.js",
"@ngrx/store": "../stark-core/node_modules/@ngrx/store/bundles/store.umd.js",
"@ngrx/effects": "../stark-core/node_modules/@ngrx/effects/bundles/effects.umd.js",
"@ngx-translate/core": "../stark-core/node_modules/@ngx-translate/core/bundles/ngx-translate-core.umd.js",
"@uirouter/angular": "../stark-core/node_modules/@uirouter/angular/_bundles/ui-router-ng2.js",
"@uirouter/core": "../stark-core/node_modules/@uirouter/core/lib/index.js",
"@uirouter/rx": "../stark-core/node_modules/@uirouter/rx/lib/index.js",
cerialize: "../stark-core/node_modules/cerialize/index.js",
"class-validator": "../stark-core/node_modules/class-validator/index.js",
"deep-freeze-strict": "../stark-core/node_modules/deep-freeze-strict/index.js",
ibantools: "../stark-core/node_modules/ibantools/build/ibantools.js",
"lodash-es": "../stark-core/node_modules/lodash-es/lodash.js",
"lodash-es/cloneDeep": "../stark-core/node_modules/lodash-es/cloneDeep.js",
"lodash-es/floor": "../stark-core/node_modules/lodash-es/floor.js",
"lodash-es/isEmpty": "../stark-core/node_modules/lodash-es/isEmpty.js",
"lodash-es/noop": "../stark-core/node_modules/lodash-es/noop.js",
"lodash-es/reduce": "../stark-core/node_modules/lodash-es/reduce.js",
moment: "../stark-core/node_modules/moment/moment.js"
}
}
};

// start customizing the KarmaCI configuration from stark-testing
const starkRBACSpecificConfiguration = {
...defaultKarmaConfig,
// add missing files due to "@nationalbankbelgium/stark-rbac" imports used in mock files of the testing sub-package
files: [...defaultKarmaConfig.files, ...karmaTypescriptFiles],
karmaTypescriptConfig: {
...defaultKarmaConfig.karmaTypescriptConfig,
bundlerOptions: {
...defaultKarmaConfig.karmaTypescriptConfig.bundlerOptions,
// change the module resolution for the KarmaTypescript bundler
...karmaTypescriptBundlerAliasResolution,
// Overwrite the karmaTypescriptConfig to pass the correct preset to karma-typescript-es6-transform
transforms: [
require("../stark-testing/node_modules/karma-typescript-angular2-transform"),
require("../stark-testing/node_modules/karma-typescript-es6-transform")({
presets: [helpers.root("../stark-testing/node_modules/babel-preset-env")] // add preset in a way that the package can find it
})
]
}
}
};
const rawKarmaConfig = require("../karma.conf.js").rawKarmaConfig;

// export the configuration function that karma expects and simply return the stark configuration
module.exports = {
default: function(config) {
return config.set(starkRBACSpecificConfiguration);
},
karmaTypescriptBundlerAliasResolution: karmaTypescriptBundlerAliasResolution,
karmaTypescriptFiles: karmaTypescriptFiles
module.exports = config => {
return config.set(rawKarmaConfig);
};
34 changes: 3 additions & 31 deletions packages/stark-ui/karma.conf.ci.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,11 @@
const helpers = require("../stark-testing/helpers");

/**
* Load karma config from Stark
* Load packages karma config
*/
const defaultKarmaCIConfig = require("../stark-testing/karma.conf.ci.js").rawKarmaConfig;
const karmaTypescriptBundlerAlias = require("./karma.conf").karmaTypescriptBundlerAlias;
const karmaTypescriptFiles = require("./karma.conf").karmaTypescriptFiles;

// start customizing the KarmaCI configuration from stark-testing
const starkUiSpecificConfiguration = {
...defaultKarmaCIConfig,
// change the path of the report so that Coveralls takes the right path to the source files
coverageIstanbulReporter: { ...defaultKarmaCIConfig.coverageIstanbulReporter, dir: helpers.root("reports/coverage/packages") },
// add missing files due to "@nationalbankbelgium/stark-ui" imports used in mock files of the testing sub-package
files: [...defaultKarmaCIConfig.files, ...karmaTypescriptFiles],
karmaTypescriptConfig: {
...defaultKarmaCIConfig.karmaTypescriptConfig,
bundlerOptions: {
...defaultKarmaCIConfig.karmaTypescriptConfig.bundlerOptions,
// change the module resolution for the KarmaTypescript bundler
resolve: {
alias: karmaTypescriptBundlerAlias
},
// Overwrite the karmaTypescriptConfig to pass the correct preset to karma-typescript-es6-transform
transforms: [
require("../stark-testing/node_modules/karma-typescript-angular2-transform"),
require("../stark-testing/node_modules/karma-typescript-es6-transform")({
presets: [helpers.root("../stark-testing/node_modules/babel-preset-env")] // add preset in a way that the package can find it
})
]
}
}
};
const rawKarmaConfig = require("../karma.conf.ci.js").rawKarmaConfig;

// export the configuration function that karma expects and simply return the stark configuration
module.exports = config => {
return config.set(starkUiSpecificConfiguration);
return config.set(rawKarmaConfig);
};
Loading