Skip to content

Commit 9634068

Browse files
author
Graham Butler
committed
add basic boilerplate
1 parent 409ffe0 commit 9634068

16 files changed

+11062
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
# boilerplate
2-
boilerplate for custom element repos
2+
Boilerplate for custom element repos.
3+
4+
To set up a new custom element:
5+
6+
1. Open `karma.base.js` and change line 8, `sauceConfiguration.testName` to reflect the correct element
7+
2. In each of the `karma.conf.**.**` files, change the path on line 6 to the point to the correct element
8+
3. In the `test` folder, replace all references to `AuthorElement` in all instances of `sanity.js` with the correct class
9+
4. In the same folder, update the script tags in each instance of `test.html` to point to the correct file
10+
5. In `rollup.release.config.js` change the variable declarations at the top to point to the correct file

clean.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const fs = require('fs-extra')
2+
const dist = require('path').join('./dist')
3+
4+
if (fs.existsSync(dist)) {
5+
fs.removeSync(dist)
6+
}

karma.base.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Karma configuration
2+
require('localenvironment')
3+
4+
var browserslist = require('browserslist')
5+
var reporterEngines = ['spec']
6+
// var reporterEngines = ['spec', 'coverage']
7+
var sauceConfiguration = { // eslint-disable-line no-unused-vars
8+
testName: 'Author.io Custom Element',
9+
build: process.env.SEMAPHORE_BUILD_NUMBER || 1,
10+
recordVideo: false,
11+
recordScreenshots: false
12+
}
13+
14+
var b = {}
15+
Object.keys(browserslist.data).filter(browser => {
16+
return /op_|opera|ie_mob|samsung/i.exec(browser) === null
17+
}).map(browserName => {
18+
var browser = browserslist.data[browserName]
19+
return `${browser.name} ${browser.released.pop()}`
20+
}).forEach(function (item, index, arr) {
21+
item = item.split(' ')
22+
var attr = (item[0] === 'edge' ? 'microsoft' : '') + item[0].toLowerCase()
23+
24+
if (attr === 'ie') {
25+
attr = 'internet explorer'
26+
}
27+
28+
b[attr] = item[1]
29+
})
30+
31+
// Construct Browser Testing List
32+
var browsers = {}
33+
var keys = Object.keys(b)
34+
35+
for (var i = 0; i < keys.length; i++) {
36+
var brwsr = keys[i].replace(/\.|\s/, '_')
37+
38+
browsers['sl_' + brwsr + '_' + b[keys[i]].replace(/\.|\s/, '_')] = {
39+
base: 'SauceLabs',
40+
browserName: keys[i],
41+
version: b[keys[i]]
42+
}
43+
}
44+
45+
browsers['sl_chrome_45'] = {
46+
base: 'SauceLabs',
47+
browserName: 'chrome',
48+
version: '45'
49+
}
50+
51+
browsers['sl_firefox_50'] = {
52+
base: 'SauceLabs',
53+
browserName: 'firefox',
54+
version: '50'
55+
}
56+
57+
// console.log(JSON.stringify(browsers, null, 2))
58+
var chalk = require('chalk')
59+
var rows = [[chalk.bold('Browser'), chalk.bold('Version')]]
60+
Object.keys(browsers).sort().forEach(slbrowser => {
61+
rows.push([browsers[slbrowser].browserName, browsers[slbrowser].version])
62+
})
63+
64+
var tablemaker = require('table').table
65+
console.log(tablemaker(rows, {
66+
columns: {
67+
1: {
68+
alignment: 'right'
69+
}
70+
}
71+
}))
72+
73+
module.exports = {
74+
tablemaker,
75+
chalk,
76+
browserslist,
77+
reporterEngines,
78+
sauceConfiguration
79+
}

karma.conf.es5.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
const base = require('./karma.base')
2+
3+
var getFiles = function () {
4+
var files = [
5+
{
6+
pattern: require('path').join(process.cwd(), './dist/author-element.es5.js'),
7+
nocache: true
8+
}
9+
]
10+
11+
// Run all tests by default
12+
let testfiles = 'test/es5/*.js'
13+
14+
return files.concat([
15+
testfiles,
16+
'test/es5/test.html'
17+
])
18+
}
19+
20+
console.log(base.tablemaker([[base.chalk.bold('Included Files')]].concat(getFiles().map(file => { return [file] }))))
21+
22+
module.exports = function (config) {
23+
config.set({
24+
25+
plugins: [
26+
require('karma-browserify'),
27+
require('tape'),
28+
require('karma-tap'),
29+
require('karma-spec-reporter'),
30+
require('karma-chrome-launcher'),
31+
// require('karma-firefox-launcher'),
32+
// require('karma-safari-launcher'),
33+
// require('karma-ie-launcher'),
34+
// require('karma-edge-launcher'),
35+
// require('karma-phantomjs-launcher'),
36+
// require('karma-sauce-launcher'),
37+
require('karma-html2js-preprocessor')
38+
],
39+
40+
// base path that will be used to resolve all patterns (eg. files, exclude)
41+
basePath: '',
42+
43+
// frameworks to use
44+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
45+
frameworks: ['tap', 'browserify'],
46+
47+
// list of files / patterns to load in the browser
48+
files: getFiles(),
49+
50+
// list of files to exclude
51+
exclude: [],
52+
53+
// preprocess matching files before serving them to the browser
54+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
55+
preprocessors: {
56+
'test/es5/**/*.js': ['browserify'],
57+
'test/es5/test.html': 'html2js'
58+
// , 'test/lib/**/*.js': 'coverage'
59+
},
60+
61+
// coverageReporter: {
62+
// type : 'html',
63+
// dir : 'coverage/'
64+
// },
65+
66+
// test results reporter to use
67+
// possible values: 'dots', 'progress'
68+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
69+
reporters: base.reporterEngines, // ['progress'],
70+
71+
// web server port
72+
port: 9876,
73+
74+
// enable / disable colors in the output (reporters and logs)
75+
colors: true,
76+
77+
// level of logging
78+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
79+
logLevel: config.LOG_DEBUG,
80+
81+
// enable / disable watching file and executing tests whenever any file changes
82+
autoWatch: false,
83+
84+
// start these browsers
85+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
86+
browsers: ['Chrome'],
87+
88+
// Continuous Integration mode
89+
// if true, Karma captures browsers, runs the tests and exits
90+
singleRun: true,
91+
92+
// Concurrency level
93+
// how many browser should be started simultanous
94+
concurrency: 3
95+
})
96+
}

karma.conf.es6-modules.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
const base = require('./karma.base')
2+
3+
var getFiles = function () {
4+
var files = [
5+
{
6+
pattern: require('path').join(process.cwd(), './author-element.js'),
7+
nocache: true,
8+
type: 'module'
9+
}
10+
]
11+
12+
// Run all tests by default
13+
let testfiles = 'test/es6-modules/*.js'
14+
15+
return files.concat([
16+
testfiles,
17+
'test/es6-modules/test.html'
18+
])
19+
}
20+
21+
console.log(base.tablemaker([[base.chalk.bold('Included Files')]].concat(getFiles().map(file => { return [file] }))))
22+
23+
module.exports = function (config) {
24+
config.set({
25+
26+
plugins: [
27+
require('karma-browserify'),
28+
require('tape'),
29+
require('karma-tap'),
30+
require('karma-spec-reporter'),
31+
require('karma-chrome-launcher'),
32+
// require('karma-firefox-launcher'),
33+
// require('karma-safari-launcher'),
34+
// require('karma-ie-launcher'),
35+
// require('karma-edge-launcher'),
36+
// require('karma-phantomjs-launcher'),
37+
// require('karma-sauce-launcher'),
38+
require('karma-html2js-preprocessor')
39+
],
40+
41+
browserify: {
42+
transform: [ 'rollupify' ]
43+
},
44+
45+
// base path that will be used to resolve all patterns (eg. files, exclude)
46+
basePath: '',
47+
48+
// frameworks to use
49+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
50+
frameworks: ['tap', 'browserify'],
51+
52+
// list of files / patterns to load in the browser
53+
files: getFiles(),
54+
55+
// list of files to exclude
56+
exclude: [],
57+
58+
// preprocess matching files before serving them to the browser
59+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
60+
preprocessors: {
61+
'test/es6-modules/**/*.js': ['browserify'],
62+
'test/es6-modules/test.html': 'html2js'
63+
// , 'test/lib/**/*.js': 'coverage'
64+
},
65+
66+
// coverageReporter: {
67+
// type : 'html',
68+
// dir : 'coverage/'
69+
// },
70+
71+
// test results reporter to use
72+
// possible values: 'dots', 'progress'
73+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
74+
reporters: base.reporterEngines, // ['progress'],
75+
76+
// web server port
77+
port: 9876,
78+
79+
// enable / disable colors in the output (reporters and logs)
80+
colors: true,
81+
82+
// level of logging
83+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
84+
logLevel: config.LOG_DEBUG,
85+
86+
// enable / disable watching file and executing tests whenever any file changes
87+
autoWatch: false,
88+
89+
// start these browsers
90+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
91+
browsers: ['Chrome'],
92+
93+
// Continuous Integration mode
94+
// if true, Karma captures browsers, runs the tests and exits
95+
singleRun: true,
96+
97+
// Concurrency level
98+
// how many browser should be started simultanous
99+
concurrency: 3
100+
})
101+
}

karma.conf.es6.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
const base = require('./karma.base')
2+
3+
var getFiles = function () {
4+
var files = [
5+
{
6+
pattern: require('path').join(process.cwd(), './dist/author-element.js'),
7+
nocache: true
8+
}
9+
]
10+
11+
// Run all tests by default
12+
let testfiles = 'test/es6/*.js'
13+
14+
return files.concat([
15+
testfiles,
16+
'test/es6/test.html'
17+
])
18+
}
19+
20+
console.log(base.tablemaker([[base.chalk.bold('Included Files')]].concat(getFiles().map(file => { return [file] }))))
21+
22+
module.exports = function (config) {
23+
config.set({
24+
25+
plugins: [
26+
require('karma-browserify'),
27+
require('tape'),
28+
require('karma-tap'),
29+
require('karma-spec-reporter'),
30+
require('karma-chrome-launcher'),
31+
// require('karma-firefox-launcher'),
32+
// require('karma-safari-launcher'),
33+
// require('karma-ie-launcher'),
34+
// require('karma-edge-launcher'),
35+
// require('karma-phantomjs-launcher'),
36+
// require('karma-sauce-launcher'),
37+
require('karma-html2js-preprocessor')
38+
],
39+
40+
// base path that will be used to resolve all patterns (eg. files, exclude)
41+
basePath: '',
42+
43+
// frameworks to use
44+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
45+
frameworks: ['tap', 'browserify'],
46+
47+
// list of files / patterns to load in the browser
48+
files: getFiles(),
49+
50+
// list of files to exclude
51+
exclude: [],
52+
53+
// preprocess matching files before serving them to the browser
54+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
55+
preprocessors: {
56+
'test/es6/**/*.js': ['browserify'],
57+
'test/es6/test.html': 'html2js'
58+
// , 'test/lib/**/*.js': 'coverage'
59+
},
60+
61+
// coverageReporter: {
62+
// type : 'html',
63+
// dir : 'coverage/'
64+
// },
65+
66+
// test results reporter to use
67+
// possible values: 'dots', 'progress'
68+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
69+
reporters: base.reporterEngines, // ['progress'],
70+
71+
// web server port
72+
port: 9876,
73+
74+
// enable / disable colors in the output (reporters and logs)
75+
colors: true,
76+
77+
// level of logging
78+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
79+
logLevel: config.LOG_DEBUG,
80+
81+
// enable / disable watching file and executing tests whenever any file changes
82+
autoWatch: false,
83+
84+
// start these browsers
85+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
86+
browsers: ['Chrome'],
87+
88+
// Continuous Integration mode
89+
// if true, Karma captures browsers, runs the tests and exits
90+
singleRun: true,
91+
92+
// Concurrency level
93+
// how many browser should be started simultanous
94+
concurrency: 3
95+
})
96+
}

0 commit comments

Comments
 (0)