Skip to content

Commit 8a2a47b

Browse files
author
Ben Monro
committed
fix: added linting
1 parent 2fe539a commit 8a2a47b

File tree

9 files changed

+152
-62
lines changed

9 files changed

+152
-62
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.DS_Store
22
node_modules
33
public/bundle.*
4+
coverage
5+
dist

.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": false,
6+
"singleQuote": true,
7+
"trailingComma": "all",
8+
"bracketSpacing": false,
9+
"jsxBracketSameLine": false,
10+
"proseWrap": "always"
11+
}

jest.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
const { jest: jestConfig } = require("kcd-scripts/config");
1+
const { jest: jestConfig } = require('kcd-scripts/config');
22

33
const config = Object.assign(jestConfig, {
4-
roots: ["tests"],
5-
testMatch: ["/**/*.spec.js"],
4+
roots: ['tests'],
5+
testMatch: ['/**/*.spec.js'],
66
transform: {
77
...jestConfig.transform,
8-
"\\.svelte$": "./tests/transform"
8+
'\\.svelte$': './tests/transform'
99
},
1010
transformIgnorePatterns: [
1111
...jestConfig.transformIgnorePatterns,
12-
"/node_modules/(?!svelte).+\\.js$"
12+
'/node_modules/(?!svelte).+\\.js$'
1313
],
14-
moduleFileExtensions: [...jestConfig.moduleFileExtensions, "svelte"]
14+
moduleFileExtensions: [...jestConfig.moduleFileExtensions, 'svelte']
1515
});
1616
module.exports = config;

package-lock.json

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"dom-testing-library": "^4.0.0",
88
"esm": "^3.2.22",
99
"jest": "^24.7.1",
10+
"jest-dom": "^3.1.2",
1011
"kcd-scripts": "^1.2.1",
1112
"npm-run-all": "^4.1.5",
1213
"rollup": "^1.10.1",
@@ -20,14 +21,31 @@
2021
"svelte-jest": "^0.2.0"
2122
},
2223
"scripts": {
23-
"build": "rollup -c",
24-
"autobuild": "rollup -c -w",
24+
"lint": "kcd-scripts lint",
25+
"validate": "kcd-scripts validate",
26+
"build": "kcd-scripts build",
27+
"build:example": "rollup -c",
28+
"autobuild:example": "rollup -c -w",
2529
"dev": "run-p start:dev autobuild",
2630
"start": "sirv public",
2731
"start:dev": "sirv public --dev",
2832
"test": "kcd-scripts test --no-watch --config=jest.config.js"
2933
},
3034
"dependencies": {
3135
"@babel/runtime": "^7.4.3"
32-
}
36+
},
37+
"eslintConfig": {
38+
"extends": "./node_modules/kcd-scripts/eslint.js",
39+
"rules": {
40+
"react/prop-types": "off",
41+
"import/no-unassigned-import": "off",
42+
"import/named": "off"
43+
}
44+
},
45+
"eslintIgnore": [
46+
"node_modules",
47+
"coverage",
48+
"dist",
49+
"public"
50+
]
3351
}

src/index.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
import { getQueriesForElement } from "dom-testing-library";
1+
import {getQueriesForElement} from 'dom-testing-library'
22

3-
export * from "dom-testing-library";
4-
let mountedContainers = new Set();
3+
export * from 'dom-testing-library'
4+
const mountedContainers = new Set()
55
export const render = (Component, props) => {
6-
const container = document.body.appendChild(document.createElement("div"));
6+
const container = document.body.appendChild(document.createElement('div'))
77

8-
let rendered = new Component({
8+
const rendered = new Component({
99
target: container,
10-
props
11-
});
10+
props,
11+
})
1212

13-
mountedContainers.add(rendered);
13+
mountedContainers.add(rendered)
1414
return {
15-
...getQueriesForElement(document.body)
16-
};
17-
};
18-
export const cleanup = () => {
19-
mountedContainers.forEach(cleanupAtContainer);
20-
};
15+
...getQueriesForElement(document.body),
16+
}
17+
}
2118

2219
const cleanupAtContainer = container => {
23-
container.$destroy();
24-
mountedContainers.delete(container);
25-
};
20+
container.$destroy()
21+
mountedContainers.delete(container)
22+
}
23+
24+
export const cleanup = () => {
25+
mountedContainers.forEach(cleanupAtContainer)
26+
}

tests/compile.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
const rollup = require("rollup");
2-
const esm = require("esm");
1+
const rollup = require('rollup')
2+
const esm = require('esm')
33

4-
const config = esm(module)("../rollup.config");
4+
const config = esm(module)('../rollup.config')
55

66
function generateOptions(filePath, name) {
77
return {
8-
input: { input: filePath, plugins: config.default.plugins },
8+
input: {input: filePath, plugins: config.default.plugins},
99
output: {
1010
file: `./dist/test/${name}.js`,
11-
format: "cjs"
12-
}
13-
};
11+
format: 'cjs',
12+
},
13+
}
1414
}
1515

1616
function compile(filePath, name) {
17-
const { input, output } = generateOptions(filePath, name);
17+
const {input, output} = generateOptions(filePath, name)
1818

19-
return rollup.rollup(input).then(bundle => bundle.generate(output));
19+
return rollup.rollup(input).then(bundle => bundle.generate(output))
2020
}
2121

22-
module.exports = { compile };
22+
module.exports = {compile}

tests/queries.spec.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
import App from "./example/App.svelte";
2-
import { render, fireEvent, waitForElement, cleanup } from "../src";
1+
import {render, fireEvent, waitForElement, cleanup} from '../src'
2+
import App from './example/App.svelte'
3+
import 'jest-dom/extend-expect'
34

4-
afterEach(cleanup);
5-
describe("queries", () => {
6-
test("getByText", () => {
7-
const { getByText } = render(App, { name: "world" });
5+
afterEach(cleanup)
6+
describe('queries', () => {
7+
test('getByText', () => {
8+
const {getByText} = render(App, {name: 'world'})
89

9-
expect(getByText("Hello world!"));
10-
});
10+
expect(getByText('Hello world!')).toBeInTheDocument()
11+
})
1112

12-
test("click button", async () => {
13-
const { getByText } = render(App, { name: "world" });
13+
test('click button', async () => {
14+
const {getByText} = render(App, {name: 'world'})
1415

15-
fireEvent.click(getByText("Button Text"));
16+
fireEvent.click(getByText('Button Text'))
1617

17-
const button = await waitForElement(() => getByText("Button Clicked"));
18+
const button = await waitForElement(() => getByText('Button Clicked'))
1819

19-
expect(button);
20-
});
21-
});
20+
expect(button).toBeInTheDocument()
21+
})
22+
})

tests/transform.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
const deasync = require("deasync");
2-
const { compile } = require("./compile");
1+
const deasync = require('deasync')
2+
const {compile} = require('./compile')
33

44
module.exports.process = (_s, filePath, _c, _o) => {
5-
let code, map;
6-
compile(filePath, "App", {}).then(comp => {
5+
let code, map
6+
compile(filePath, 'App', {}).then(comp => {
7+
code = comp.output[0].code
8+
map = comp.output[0].map
9+
})
10+
deasync.loopWhile(() => !code && !map)
711

8-
code = comp.output[0].code;
9-
map = comp.output[0].map;
10-
});
11-
deasync.loopWhile(() => !code && !map);
12-
13-
return { code, map };
14-
};
12+
return {code, map}
13+
}

0 commit comments

Comments
 (0)