Skip to content

Commit e50f339

Browse files
authored
Replace Karma / Mocha with Jest (OctoLinker#415)
* Remove mocha / karma setup * Replace innerText with textContent to make jest working innerText is not standard and therfore not supported by jsdom. Also according to this article https://kellegous.com/j/2013/02/27/innertext-vs-textcontent/ innerText is much slower than textContent. * Drop dynamic require * Setup jest * Reimplement fixture loading * Minimal required changes to make jest working * upgrade nodejs version * Make loadPlugins an object instead of a function See https://github.com/OctoLinker/browser-extension/pull/415/files#diff-63ac5d48d83927921b7bcdb2b5a8d124R50 * fixup! Minimal required changes to make jest working * Using path.posix.join to fix Windows issues
1 parent ec40563 commit e50f339

24 files changed

+1376
-998
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Test against this version of Node.js
22
environment:
3-
nodejs_version: "6"
3+
nodejs_version: "8"
44

55
cache:
66
- "%LOCALAPPDATA%\\Yarn"

.babelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
2+
"env": {
3+
"test": {
4+
"presets": ["env"]
5+
}
6+
},
27
"plugins": [
38
"transform-object-rest-spread",
49
["transform-react-jsx", { "pragma": "h" }]

.eslintrc.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module.exports = {
22
extends: ['airbnb', 'prettier'],
3-
plugins: ['prettier', 'react', 'mocha'],
3+
plugins: ['prettier', 'react'],
44
env: {
5-
browser: true,
6-
mocha: true
5+
jest: true,
6+
browser: true
77
},
88
settings: {
99
react: {
@@ -37,15 +37,6 @@ module.exports = {
3737
'no-restricted-syntax': 0,
3838
'consistent-return': 0,
3939
'array-callback-return': 0,
40-
'mocha/no-exclusive-tests': 2,
41-
'mocha/no-skipped-tests': 2,
42-
'mocha/no-pending-tests': 2,
43-
'mocha/handle-done-callback': 2,
44-
'mocha/no-global-tests': 2,
45-
'mocha/no-return-and-callback': 2,
46-
'mocha/no-sibling-hooks': 2,
47-
'mocha/no-identical-title': 2,
48-
'mocha/no-top-level-hooks': 2
4940
},
5041
globals: {
5142
fixture: true,

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ addons:
77
- google-chrome-stable
88
language: node_js
99
node_js:
10-
- 6
10+
- 8
1111
cache:
1212
yarn: true
1313
# Use npm > 4 to fix https://github.com/npm/npm/issues/14042

karma.conf.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

lib/load-plugins.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
// Load all plugins from /lib/plugins/*/index.js.
2-
// For more information about dynamic require see
3-
// https://webpack.github.io/docs/context.html
4-
5-
export default function loadPlugins() {
6-
function requireAll(requireContext) {
7-
return requireContext
8-
.keys()
9-
.map(pluginPath => requireContext(pluginPath).default);
10-
}
11-
12-
return requireAll(require.context('./plugins', false, /[^/]*.js$/));
13-
}
1+
export { default as BowerManifest } from './plugins/bower-manifest.js';
2+
export { default as Composer } from './plugins/composer-manifest.js';
3+
export { default as CSS } from './plugins/css.js';
4+
export { default as Docker } from './plugins/docker.js';
5+
export { default as DotNetCore } from './plugins/dot-net-core.js';
6+
export { default as DotNet } from './plugins/dot-net.js';
7+
export { default as Rubygems } from './plugins/gemfile-manifest.js';
8+
export { default as Go } from './plugins/go.js';
9+
export { default as Haskell } from './plugins/haskell.js';
10+
export { default as Homebrew } from './plugins/homebrew-manifest.js';
11+
export { default as HTML } from './plugins/html.js';
12+
export { default as Java } from './plugins/java.js';
13+
export { default as JavaScript } from './plugins/javascript.js';
14+
export { default as Less } from './plugins/less.js';
15+
export {
16+
default as NodejsRelativePath,
17+
} from './plugins/nodejs-relative-path.js';
18+
export { default as NpmManifest } from './plugins/npm-manifest.js';
19+
export { default as Python } from './plugins/python.js';
20+
export { default as RequirementsTxt } from './plugins/requirements-txt.js';
21+
export { default as Ruby } from './plugins/ruby.js';
22+
export { default as Rust } from './plugins/rust.js';
23+
export { default as Sass } from './plugins/sass.js';
24+
export { default as TypeScript } from './plugins/typescript.js';
25+
export { default as Vim } from './plugins/vim.js';

lib/plugin-manager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function getPluginsForGithubClasses(plugins, classList) {
5454

5555
export default class {
5656
constructor(plugins) {
57+
plugins = Object.values(plugins);
5758
this._pluginsList = plugins;
5859
this._plugins = buildPluginCache(plugins);
5960
}

lib/plugins/go.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { join, dirname } from 'path';
1+
import { posix, dirname } from 'path';
22
import { go } from '../../packages/helper-grammar-regex-collection/index.js';
33

44
function goFile({ path, target }) {
55
const list = [];
6-
const basePath = join(dirname(path), target);
6+
const basePath = posix.join(dirname(path), target);
77
const filename = target.slice(target.lastIndexOf('/') + 1);
88

99
list.push(`/${filename}.go`);

lib/plugins/javascript.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join, dirname, extname } from 'path';
1+
import { posix, dirname, extname } from 'path';
22
import concatMap from 'concat-map';
33
import {
44
REQUIRE,
@@ -21,7 +21,7 @@ function getTopModuleName(target) {
2121
export function javascriptFile({ path, target }) {
2222
const list = [];
2323
const extName = ['.js', '.jsx', '.ts', '.tsx', '.ls', '.json'];
24-
const basePath = join(dirname(path), target);
24+
const basePath = posix.join(dirname(path), target);
2525
const pathExt = extname(path);
2626
const fileExt = extname(basePath);
2727

lib/plugins/nodejs-relative-path.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join, dirname } from 'path';
1+
import { posix, dirname } from 'path';
22
import {
33
NODEJS_RELATIVE_PATH,
44
NODEJS_RELATIVE_PATH_JOIN,
@@ -10,7 +10,7 @@ export default {
1010
name: 'NodejsRelativePath',
1111

1212
resolve({ target, path }) {
13-
return `{BASE_URL}${join(dirname(path), target)}`;
13+
return `{BASE_URL}${posix.join(dirname(path), target)}`;
1414
},
1515

1616
getPattern() {

0 commit comments

Comments
 (0)