Skip to content

Commit 846f19d

Browse files
fix(polyfill): small improvements and refactor of tests
1 parent 11f207a commit 846f19d

10 files changed

+3961
-785
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.coverage
3+
coverage
34
node_modules
45
dist
56
.npmrc

Diff for: karma.conf.js

+37-149
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,46 @@
1+
const { createDefaultConfig } = require('@open-wc/testing-karma');
2+
const merge = require('deepmerge');
3+
4+
module.exports = config => {
5+
config.set(
6+
merge(createDefaultConfig(config), {
7+
files: [
8+
// runs all files ending with .test in the test folder,
9+
// can be overwritten by passing a --grep flag. examples:
10+
//
11+
// npm run test -- --grep test/foo/bar.test.js
12+
// npm run test -- --grep test/bar/*
13+
{ pattern: config.grep ? config.grep : 'test/*.test.js', type: 'module' },
14+
],
115

2-
// Karma configuration
3-
// Generated on Mon Apr 13 2020 13:45:54 GMT-0500 (Central Daylight Time)
4-
const {readFileSync} = require('fs');
5-
const {resolve} = require('path');
6-
7-
const isCI = !!process.env.CI;
8-
const watch = !!process.argv.find(arg => arg.includes('watch')) && !isCI;
9-
const coverage = !!process.argv.find(arg => arg.includes('--coverage'));
10-
11-
const babelrc = JSON.parse(
12-
readFileSync(resolve(process.cwd(), '.babelrc'), 'utf8'),
13-
);
14-
15-
module.exports = function(config) {
16-
config.set({
17-
// base path that will be used to resolve all patterns (eg. files, exclude)
18-
basePath: '',
19-
20-
// frameworks to use
21-
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
22-
frameworks: ['jasmine', 'detectBrowsers'],
23-
24-
// plugins
25-
plugins: [
26-
'karma-jasmine',
27-
'karma-chrome-launcher',
28-
'karma-edge-launcher',
29-
'karma-firefox-launcher',
30-
'karma-ie-launcher',
31-
'karma-safarinative-launcher',
32-
'karma-detect-browsers',
33-
'karma-rollup-preprocessor',
34-
'karma-coverage-istanbul-reporter'
35-
],
36-
37-
browserNoActivityTimeout: 60000, //default 10000
38-
browserDisconnectTimeout: 10000, // default 2000
39-
browserDisconnectTolerance: 1, // default 0
40-
captureTimeout: 60000,
41-
42-
detectBrowsers: {
43-
enabled: true,
44-
usePhantomJS: false,
45-
preferHeadless: true,
46-
postDetection(availableBrowsers) {
47-
return availableBrowsers.filter(browser => browser !== 'SafariTechPreview');
48-
}
49-
},
50-
51-
coverageIstanbulReporter: {
52-
reports: ['html', 'lcovonly'],
53-
dir: '.coverage',
54-
combineBrowserReports: true,
55-
skipFilesWithNoCoverage: true,
56-
'report-config': {
57-
html: {subdir: 'html'},
58-
lcovonly: {subdir: 'lcov'},
59-
},
60-
},
61-
62-
customLaunchers: {
63-
Safari: {
64-
base: 'SafariNative',
16+
// see the karma-esm docs for all options
17+
esm: {
18+
// if you are using 'bare module imports' you will need this option
19+
nodeResolve: true,
6520
},
66-
},
67-
68-
// list of files / patterns to load in the browser
69-
files: [
70-
{ pattern: 'src/element-internals.js', watched: false },
71-
{ pattern: 'test/*.test.js', watched: false },
72-
],
73-
7421

75-
// list of files / patterns to exclude
76-
exclude: [
77-
],
22+
frameworks: [...config.frameworks, 'detectBrowsers'],
7823

79-
80-
// preprocess matching files before serving them to the browser
81-
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
82-
preprocessors: {
83-
'src/element-internals.js': ['sourceRollup'],
84-
'test/*.test.js': ['rollup'],
85-
},
86-
87-
// test results reporter to use
88-
// possible values: 'dots', 'progress'
89-
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
90-
reporters: ['progress', coverage && 'coverage-istanbul'].filter(Boolean),
91-
92-
rollupPreprocessor: {
93-
plugins: [
94-
require('rollup-plugin-commonjs')({
95-
include: 'node_modules/**',
96-
exclude: 'node_modules/@open-wc/**',
97-
}),
98-
require('@rollup/plugin-node-resolve')(),
99-
require('rollup-plugin-babel')({
100-
babelrc: false,
101-
include: ['node_modules/@open-wc/**', 'test/**'],
102-
...babelrc,
103-
plugins: ['babel-plugin-transform-async-to-promises']
104-
}),
105-
],
106-
output: {
107-
format: 'iife',
108-
name: 'tests',
24+
detectBrowsers: {
25+
enabled: config.detectBrowsers,
26+
usePhantomJS: false,
27+
preferHeadless: true,
28+
postDetection(availableBrowsers) {
29+
return availableBrowsers.filter(browser => browser !== 'SafariTechPreview');
30+
}
10931
},
110-
},
11132

112-
customPreprocessors: {
113-
sourceRollup: {
114-
base: 'rollup',
115-
options: {
116-
plugins: [
117-
require('@rollup/plugin-node-resolve')(),
118-
require('rollup-plugin-babel')({
119-
babelrc: false,
120-
...babelrc,
121-
plugins: [coverage && 'babel-plugin-istanbul'].filter(Boolean),
122-
}),
123-
],
124-
output: {
125-
format: 'iife',
126-
name: 'tests',
127-
},
128-
treeshake: false,
33+
customLaunchers: {
34+
Safari: {
35+
base: 'SafariNative',
12936
},
13037
},
131-
},
132-
133-
// web server port
134-
port: 9876,
135-
136-
137-
// enable / disable colors in the output (reporters and logs)
138-
colors: true,
139-
140-
141-
// level of logging
142-
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
143-
logLevel: config.LOG_INFO,
144-
145-
146-
// enable / disable watching file and executing tests whenever any file changes
147-
autoWatch: watch,
148-
149-
150-
// Continuous Integration mode
151-
// if true, Karma captures browsers, runs the tests and exits
152-
singleRun: !watch,
15338

154-
// Concurrency level
155-
// how many browser should be started simultaneous
156-
concurrency: Infinity
157-
})
158-
}
39+
browserNoActivityTimeout: 60000, //default 10000
40+
browserDisconnectTimeout: 10000, // default 2000
41+
browserDisconnectTolerance: 1, // default 0
42+
captureTimeout: 60000,
43+
}),
44+
);
45+
return config;
46+
};

0 commit comments

Comments
 (0)