Skip to content

Commit

Permalink
style: codeformat with Prettier (#532)
Browse files Browse the repository at this point in the history
* chore: add prettier

* style: format with prettier
  • Loading branch information
egilsster committed Sep 4, 2020
1 parent c679570 commit 57f65f1
Show file tree
Hide file tree
Showing 96 changed files with 2,430 additions and 2,363 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"sourceType": "module"
},
"rules": {
"arrow-parens": [2, "as-needed"],
"prettier/prettier": "error",
"import/no-extraneous-dependencies": [
2,
{
Expand Down Expand Up @@ -56,5 +56,6 @@
"max-classes-per-file": 0,
"prefer-object-spread": 0
},
"extends": ["airbnb"]
"extends": ["airbnb", "prettier", "prettier/react"],
"plugins": ["prettier"]
}
81 changes: 42 additions & 39 deletions aw.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,76 @@ const cmd = process.argv.slice(2).shift();

module.exports = {
coverage: true,
url: 'http://localhost:9677/examples/index.html',
url: "http://localhost:9677/examples/index.html",
mocks: [
['**/*.{scss,less,css,html}'],
['./foobar-virtual.html', '"<div>hello world</div>"'],
['mocked-special', './examples/react/test/internal-aw-tests/button-mock.js'],
["**/*.{scss,less,css,html}"],
["./foobar-virtual.html", '"<div>hello world</div>"'],
[
"mocked-special",
"./examples/react/test/internal-aw-tests/button-mock.js",
],
],
nyc: {
exclude: [
'**/*.html',
'**/*.spec.*',
'**/cli/src/index.js',
'**/transform/src/index.js',
'**/browser-shim.js',
'**/commands/aw',
'**/examples/main.js',
'**/examples/react/src/full-match.js',
"**/*.html",
"**/*.spec.*",
"**/cli/src/index.js",
"**/transform/src/index.js",
"**/browser-shim.js",
"**/commands/aw",
"**/examples/main.js",
"**/examples/react/src/full-match.js",
],
},
mocha: {
reporter: 'spec',
reporter: "spec",
},
// Protractor mochaOpts
mochaOpts: {
reporterOptions: {
name: '@after-work.js',
version: 'next',
name: "@after-work.js",
version: "next",
},
},
'transform.typescript.babelOptions': {
"transform.typescript.babelOptions": {
presets: [
[
'@babel/preset-env',
"@babel/preset-env",
{
targets: {
browsers: ['last 2 versions', 'safari >= 7'],
node: 'current',
browsers: ["last 2 versions", "safari >= 7"],
node: "current",
},
modules: cmd !== 'chrome' ? 'commonjs' : false,
modules: cmd !== "chrome" ? "commonjs" : false,
},
],
],
},
'filter.node.packages': [
'!@after-work.js/example-*(protractor|puppeteer|webpack-dev-server)',
'!@after-work.js/example-chrome-*',
"filter.node.packages": [
"!@after-work.js/example-*(protractor|puppeteer|webpack-dev-server)",
"!@after-work.js/example-chrome-*",
],
'filter.node.files': [
'!**/commands/protractor/src/config.js',
'!**/examples/chrome-*/**',
'!**/examples/protractor/**',
'!**/examples/puppeteer/**',
'!**/examples/webpack-dev-server/**',
"filter.node.files": [
"!**/commands/protractor/src/config.js",
"!**/examples/chrome-*/**",
"!**/examples/protractor/**",
"!**/examples/puppeteer/**",
"!**/examples/webpack-dev-server/**",
],
'filter.chrome.packages': ['@after-work.js/example-chrome-*'],
'filter.chrome.files': [
'**/examples/chrome-*/**',
'!**/examples/chrome-esm/**',
"filter.chrome.packages": ["@after-work.js/example-chrome-*"],
"filter.chrome.files": [
"**/examples/chrome-*/**",
"!**/examples/chrome-esm/**",
],
'filter.puppeteer.packages': ['@after-work.js/example-puppeteer'],
'filter.puppeteer.files': ['**/examples/puppeteer/**'],
'filter.protractor.files': ['**/examples/protractor/**'],
artifactsPath: 'test/__artifacts__',
"filter.puppeteer.packages": ["@after-work.js/example-puppeteer"],
"filter.puppeteer.files": ["**/examples/puppeteer/**"],
"filter.protractor.files": ["**/examples/protractor/**"],
artifactsPath: "test/__artifacts__",
http: {
port: 9677,
},
specs: ['./examples/protractor/test/hello.spec.js'],
specs: ["./examples/protractor/test/hello.spec.js"],
transform: {
exclude: ['**/chrome-esm/**'],
exclude: ["**/chrome-esm/**"],
},
};
16 changes: 8 additions & 8 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ module.exports = (api) => {
api.cache(true);
const cmd = process.argv.slice(2).shift();
switch (cmd) {
case 'chrome':
case "chrome":
return {
presets: [
[
'@babel/preset-env',
"@babel/preset-env",
{
targets: {
browsers: ['last 2 versions', 'safari >= 7'],
browsers: ["last 2 versions", "safari >= 7"],
},
modules: 'amd',
modules: "amd",
},
],
],
ignore: ['**/ignore.js'],
ignore: ["**/ignore.js"],
};
default:
return {
presets: [
[
'@babel/preset-env',
"@babel/preset-env",
{
targets: { node: 'current' },
targets: { node: "current" },
},
],
],
plugins: ['@babel/plugin-transform-react-jsx'],
plugins: ["@babel/plugin-transform-react-jsx"],
};
}
};
2 changes: 1 addition & 1 deletion commands/aw/src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require('@after-work.js/cli');
require("@after-work.js/cli");
48 changes: 26 additions & 22 deletions commands/cdp/src/browser-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
const origRun = m.run.bind(m);

m.run = () => {
win.awMediator.emit('started', m.suite.suites.length);
win.awMediator.emit("started", m.suite.suites.length);
m.runner = origRun(() => {
setTimeout(() => win.awMediator.emit('ended', m.runner.stats), 0);
setTimeout(() => win.awMediator.emit("ended", m.runner.stats), 0);
});
return m.runner;
};
}
Object.defineProperty(win, 'mocha', {
Object.defineProperty(win, "mocha", {
get() {
return undefined;
},
Expand All @@ -24,22 +24,22 @@
configurable: true,
});

Object.defineProperty(win, 'Mocha', {
Object.defineProperty(win, "Mocha", {
get() {
return undefined;
},
set(m) {
delete win.Mocha;
win.Mocha = m;

m.process.nextTick = cb => cb();
m.process.nextTick = (cb) => cb();
m.process.stdout._write = (chunks, encoding, cb) => {
const output = chunks.toString ? chunks.toString() : chunks;
console.info(output);
m.process.nextTick(cb);
};

win.awMediator.emit('width');
win.awMediator.emit("width");
},
configurable: true,
});
Expand All @@ -52,37 +52,41 @@
const origLog = console.log;

console.format = function (f) {
if (typeof f !== 'string') {
return Array.prototype.map.call(arguments, arg => {
try {
return JSON.stringify(arg);
} catch (_) {
return '[Circular]';
}
}).join(' ');
if (typeof f !== "string") {
return Array.prototype.map
.call(arguments, (arg) => {
try {
return JSON.stringify(arg);
} catch (_) {
return "[Circular]";
}
})
.join(" ");
}
let i = 1,
args = arguments,
len = args.length,
str = String(f).replace(/%[sdj%]/g, x => {
if (x === '%%') return '%';
str = String(f).replace(/%[sdj%]/g, (x) => {
if (x === "%%") return "%";
if (i >= len) return x;
switch (x) {
case '%s': return String(args[i++]);
case '%d': return Number(args[i++]);
case '%j':
case "%s":
return String(args[i++]);
case "%d":
return Number(args[i++]);
case "%j":
try {
return JSON.stringify(args[i++]);
} catch (_) {
return '[Circular]';
return "[Circular]";
}
default:
return x;
}
}),
x;
for (x = args[i]; i < len; x = args[++i]) {
if (x === null || typeof x !== 'object') {
if (x === null || typeof x !== "object") {
str += ` ${x}`;
} else {
str += ` ${JSON.stringify(x)}`;
Expand All @@ -99,4 +103,4 @@
origLog.call(console, console.format(...arguments));
};
}
}(window));
})(window);
26 changes: 13 additions & 13 deletions commands/cdp/src/connect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint object-curly-newline: 0, max-len: 0 */
const fs = require('fs');
const path = require('path');
const CDP = require('chrome-remote-interface');
const fs = require("fs");
const path = require("path");
const CDP = require("chrome-remote-interface");

const injectMediator = `
(function (win) {
Expand All @@ -17,7 +17,7 @@ const injectMediator = `
`;

function getContent(filePath) {
return fs.readFileSync(filePath, 'utf-8');
return fs.readFileSync(filePath, "utf-8");
}

module.exports = async function connect(argv, files, presetEnv, debugging) {
Expand All @@ -34,7 +34,7 @@ module.exports = async function connect(argv, files, presetEnv, debugging) {
})}`;
const injectAwFiles = `window.awFiles = ${JSON.stringify(files)}`;
const injectAwDevtools = `window.awDevtools = ${JSON.stringify(
argv.chrome.devtools,
argv.chrome.devtools
)}`;
const injectAwDebugging = `window.awDebugging = ${JSON.stringify(debugging)}`;

Expand All @@ -47,13 +47,13 @@ module.exports = async function connect(argv, files, presetEnv, debugging) {
Console.enable(),
]);
const sourceMapSupport = `${path.dirname(
require.resolve('source-map-support'),
require.resolve("source-map-support")
)}/browser-source-map-support.js`;
await Page.addScriptToEvaluateOnNewDocument({
source: `${getContent(sourceMapSupport)};`,
});
await Page.addScriptToEvaluateOnNewDocument({
source: 'sourceMapSupport.install();',
source: "sourceMapSupport.install();",
});
await Page.addScriptToEvaluateOnNewDocument({ source: injectMediator });
await Page.addScriptToEvaluateOnNewDocument({
Expand All @@ -67,23 +67,23 @@ module.exports = async function connect(argv, files, presetEnv, debugging) {
source: injectAwDebugging,
});
await Page.addScriptToEvaluateOnNewDocument({
source: getContent(path.join(__dirname, 'browser-shim.js')),
source: getContent(path.join(__dirname, "browser-shim.js")),
});
if (presetEnv) {
await Page.addScriptToEvaluateOnNewDocument({
source: getContent(require.resolve('chai/chai')),
source: getContent(require.resolve("chai/chai")),
});
await Page.addScriptToEvaluateOnNewDocument({
source: 'expect = chai.expect;',
source: "expect = chai.expect;",
});
await Page.addScriptToEvaluateOnNewDocument({
source: getContent(require.resolve('chai-subset/lib/chai-subset')),
source: getContent(require.resolve("chai-subset/lib/chai-subset")),
});
await Page.addScriptToEvaluateOnNewDocument({
source: getContent(require.resolve('sinon-chai/lib/sinon-chai')),
source: getContent(require.resolve("sinon-chai/lib/sinon-chai")),
});
await Page.addScriptToEvaluateOnNewDocument({
source: getContent(require.resolve('sinon/pkg/sinon')),
source: getContent(require.resolve("sinon/pkg/sinon")),
});
}
return client;
Expand Down

0 comments on commit 57f65f1

Please sign in to comment.