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

refactor(checkbox): Add Jasmine test for checkbox foundation. #5299

Merged
merged 18 commits into from
Dec 9, 2019
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
180 changes: 118 additions & 62 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ const webpackConfig = require('./webpack.config')[1];

const USING_TRAVISCI = Boolean(process.env.TRAVIS);
const USING_SL = Boolean(process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY);
// If true, runs new suite of Jasmine foundation unit tests.
// Otherwise, runs old Mocha unit tests.
const USE_JASMINE = Boolean(process.env.USE_JASMINE);
joyzhong marked this conversation as resolved.
Show resolved Hide resolved

// Files to include in Jasmine tests.
const FILES_TO_USE = [
'packages/*/!(node_modules)/**/!(*.d).ts',
'packages/*/!(*.d).ts',
'testing/**/*.ts',
];

const HEADLESS_LAUNCHERS = {
/** See https://github.com/travis-ci/travis-ci/issues/8836#issuecomment-348248951 */
Expand Down Expand Up @@ -63,79 +73,125 @@ const istanbulInstrumenterLoader = {
include: path.resolve('./packages'),
};

module.exports = function(config) {
config.set({
basePath: '',
// Refer https://github.com/karma-runner/karma-mocha
frameworks: ['mocha'],
files: [
// Refer https://github.com/babel/karma-babel-preprocessor
'node_modules/@babel/polyfill/dist/polyfill.js',
'test/unit/index.js',
],
preprocessors: {
'test/unit/index.js': ['webpack', 'sourcemap'],
const mochaConfig = {
basePath: '',
// Refer https://github.com/karma-runner/karma-mocha
frameworks: ['mocha'],
files: [
// Refer https://github.com/babel/karma-babel-preprocessor
'node_modules/@babel/polyfill/dist/polyfill.js',
'test/unit/index.js',
],
preprocessors: {
'test/unit/index.js': ['webpack', 'sourcemap'],
},
reporters: ['progress', 'coverage-istanbul'],

coverageIstanbulReporter: {
'dir': 'coverage',
'reports': ['html', 'lcovonly', 'json'],
'report-config': {
lcovonly: {subdir: '.'},
json: {subdir: '.', file: 'coverage.json'},
},
// Set 'emitWarning = true' to NOT fail tests if the thresholds are not met
'emitWarning': false,
'thresholds': {
statements: 95,
branches: 95,
lines: 95,
functions: 95,
},
},

client: {
mocha: {
reporter: 'html',
ui: 'qunit',

// Number of milliseconds to wait for an individual `test(...)` function to complete.
// The default is 2000.
timeout: 10000,
},
},

webpackMiddleware: {
noInfo: true,
stats: 'minimal',
},
};

const jasmineConfig = {
basePath: '',
files: FILES_TO_USE,
frameworks: ['jasmine', 'karma-typescript'],
karmaTypescriptConfig: {
coverageOptions: {
threshold: {
global: {
// TODO: Raise threshold to at least 90% after more tests have been migrated.
statements: 80,
branches: 80,
functions: 50,
lines: 80,
excludes: [
'testing/**/*.ts',
'packages/!(mdc-checkbox)/**/*',
'packages/**/component.ts', // Jasmine tests cover foundation/adapter only.
],
},
},
},
reports: {
html: 'coverage',
lcovonly: 'coverage',
json: {
directory: 'coverage',
filename: 'coverage.json',
},
},
reporters: ['progress', 'coverage-istanbul'],
tsconfig: './tsconfig.json',
},
preprocessors: FILES_TO_USE.reduce((obj, file) => {
obj[file] = 'karma-typescript';
return obj;
}, {}),
reporters: ['progress', 'karma-typescript'],
};

module.exports = function(config) {
config.set(Object.assign(USE_JASMINE ? jasmineConfig : mochaConfig, {
logLevel: config.LOG_INFO,
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
browsers: browsers,
browserDisconnectTimeout: 40000,
browserNoActivityTimeout: 120000,
captureTimeout: 240000,
concurrency: USING_SL ? 4 : Infinity,
customLaunchers: customLaunchers,
}));

coverageIstanbulReporter: {
'dir': 'coverage',
'reports': ['html', 'lcovonly', 'json'],
'report-config': {
lcovonly: {subdir: '.'},
json: {subdir: '.', file: 'coverage.json'},
},
// 'emitWarning' causes the tests to fail if the thresholds are not met
'emitWarning': false,
'thresholds': {
statements: 95,
branches: 95,
lines: 95,
functions: 95,
},
},

client: {
mocha: {
reporter: 'html',
ui: 'qunit',

// Number of milliseconds to wait for an individual `test(...)` function to complete.
// The default is 2000.
timeout: 10000,
},
},

// Refer https://github.com/webpack-contrib/karma-webpack
webpack: Object.assign({}, webpackConfig, {
plugins: [], // Exclude UglifyJs plugin from test build.
mode: 'development',
module: Object.assign({}, webpackConfig.module, {
// Cover source files when not debugging tests. Otherwise, omit coverage instrumenting to get
// uncluttered source maps.
rules: webpackConfig.module.rules.concat(config.singleRun ? [Object.assign({
enforce: 'post',
test: /\.ts$/,
}, istanbulInstrumenterLoader), Object.assign({
test: /\.js$/,
}, istanbulInstrumenterLoader)] : []),
if (!USE_JASMINE) {
// Need to set webpack here rather than in `mochaConfig` to read `config.singleRun`.
config.set({
// Refer https://github.com/webpack-contrib/karma-webpack
webpack: Object.assign({}, webpackConfig, {
plugins: [], // Exclude UglifyJs plugin from test build.
mode: 'development',
module: Object.assign({}, webpackConfig.module, {
// Cover source files when not debugging tests. Otherwise, omit coverage instrumenting to get
// uncluttered source maps.
rules: webpackConfig.module.rules.concat(config.singleRun ? [Object.assign({
enforce: 'post',
test: /\.ts$/,
}, istanbulInstrumenterLoader), Object.assign({
test: /\.js$/,
}, istanbulInstrumenterLoader)] : []),
}),
}),
}),

webpackMiddleware: {
noInfo: true,
stats: 'minimal',
},
});
});
}

if (USING_SL) {
const sauceLabsConfig = {
Expand Down
Loading