Skip to content

Commit 8926786

Browse files
authored
Merge pull request #25 from sparksuite/polish
General polish
2 parents c440592 + 0432bfb commit 8926786

16 files changed

+394
-978
lines changed

.eslintignore

-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ coverage/
33
dist/
44
babel.config.js
55
jest-puppeteer.config.js
6-
test/puppeteer/node_modules/
7-
test/puppeteer/dist/

.eslintrc.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"plugin:@typescript-eslint/eslint-recommended",
55
"plugin:@typescript-eslint/recommended",
66
"plugin:@typescript-eslint/recommended-requiring-type-checking",
7-
"prettier",
8-
"prettier/@typescript-eslint"
7+
"prettier"
98
],
109
"env": {
1110
"es6": true,

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
7575
restore-keys: |
7676
${{ runner.os }}-yarn-
77-
- run: yarn install --frozen-lockfile --prefer-offline
77+
- run: yarn dev
7878
- run: yarn test
7979
- name: Codecov
8080
uses: codecov/codecov-action@v1

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
node_modules/
22
coverage/
33
dist/
4-
test/puppeteer/node_modules/
5-
test/puppeteer/dist/

.prettierignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
node_modules/
22
coverage/
33
dist/
4-
test/puppeteer/node_modules/
5-
test/puppeteer/dist/

babel.config.js

-13
This file was deleted.

jest.config.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { Config } from '@jest/types';
2+
// @ts-expect-error: Missing types
3+
import presetTSJest from 'ts-jest/jest-preset';
4+
import presetJestPuppeteer from 'jest-puppeteer/jest-preset.json';
5+
import merge from 'merge';
6+
7+
const config: Config.InitialOptions = {
8+
collectCoverage: true,
9+
coverageDirectory: './coverage/',
10+
collectCoverageFrom: ['<rootDir>/src/**'],
11+
verbose: true,
12+
projects: [
13+
{
14+
displayName: 'Jest',
15+
preset: 'ts-jest',
16+
testMatch: ['<rootDir>/test/*.test.ts'],
17+
},
18+
merge.recursive(presetTSJest, presetJestPuppeteer, {
19+
displayName: 'Puppeteer',
20+
testMatch: ['<rootDir>/test/puppeteer/test/*.test.ts'],
21+
}),
22+
],
23+
};
24+
25+
export default config;

package.json

+8-29
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
"dist/"
99
],
1010
"scripts": {
11-
"test": "yarn --frozen-lockfile --check-files && yarn compile && yarn link && cd test/puppeteer && yarn --frozen-lockfile --check-files && yarn link \"w3c-css-validator\" && npx webpack && cd ../../ && jest",
11+
"dev": "yarn --frozen-lockfile --check-files && yarn compile && yarn link && cd test/puppeteer && yarn --frozen-lockfile --check-files && yarn link \"w3c-css-validator\" && npx webpack",
12+
"test": "jest",
1213
"lint": "eslint --ext .js,.ts . && prettier --check '**/*.{ts,js,json,yml}'",
1314
"format": "eslint --fix --ext .js,.ts . && prettier --write '**/*.{ts,js,json,yml}'",
1415
"clean": "git clean -X -d --force && find . -type d -empty -delete",
15-
"compile": "rm -rf dist/ && tsc"
16+
"precompile": "rm -rf dist/",
17+
"compile": "tsc --project tsconfig.build.json"
1618
},
1719
"repository": {
1820
"type": "git",
@@ -32,43 +34,20 @@
3234
"homepage": "https://github.com/sparksuite/w3c-css-validator",
3335
"dependencies": {},
3436
"devDependencies": {
35-
"@babel/core": "^7.12.13",
36-
"@babel/preset-env": "^7.12.13",
37-
"@babel/preset-typescript": "^7.12.13",
3837
"@types/jest": "^26.0.20",
3938
"@types/jest-environment-puppeteer": "^4.4.1",
4039
"@types/node": "^14.14.25",
4140
"@typescript-eslint/eslint-plugin": "^4.14.2",
4241
"@typescript-eslint/parser": "^4.14.2",
4342
"eslint": "^7.19.0",
44-
"eslint-config-prettier": "^7.2.0",
43+
"eslint-config-prettier": "^8.0.0",
4544
"jest": "^26.6.3",
4645
"jest-puppeteer": "^4.4.0",
46+
"merge": "^2.1.1",
4747
"prettier": "^2.2.1",
4848
"puppeteer": "^7.1.0",
49+
"ts-jest": "^26.5.2",
50+
"ts-node": "^9.1.1",
4951
"typescript": "^4.1.3"
50-
},
51-
"jest": {
52-
"collectCoverage": true,
53-
"coverageDirectory": "./coverage/",
54-
"collectCoverageFrom": [
55-
"<rootDir>/src/**"
56-
],
57-
"verbose": true,
58-
"projects": [
59-
{
60-
"displayName": "Jest",
61-
"testMatch": [
62-
"<rootDir>/test/*.test.ts"
63-
]
64-
},
65-
{
66-
"displayName": "Puppeteer",
67-
"preset": "jest-puppeteer",
68-
"testMatch": [
69-
"<rootDir>/test/puppeteer/*.test.ts"
70-
]
71-
}
72-
]
7352
}
7453
}

test/index.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,16 @@ describe('#validateText()', () => {
4949
],
5050
});
5151
});
52+
53+
it('Does not include warnings on the result when warnings aren’t enabled', async () => {
54+
expect(await cssValidator.validateText('.foo { font-family: Georgia; }')).toStrictEqual({
55+
valid: true,
56+
errors: [],
57+
});
58+
59+
expect(await cssValidator.validateText('.foo { font-family: Georgia; }', { warningLevel: 0 })).toStrictEqual({
60+
valid: true,
61+
errors: [],
62+
});
63+
});
5264
});

test/puppeteer/index.test.ts renamed to test/puppeteer/test/index.test.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ it('Returns the validity', async () => {
3737
await page.click('#make-call');
3838

3939
await waitForResponse();
40-
expect(await page.evaluate(() => document.querySelector<HTMLHeadingElement>('#is-valid').innerText)).toBe('true');
40+
expect(await page.evaluate(() => document.querySelector<HTMLHeadingElement>('#is-valid')?.innerText)).toBe('true');
4141
});
4242

4343
it('Includes errors present in the response on the result', async () => {
4444
await page.type('#custom-css', '.foo { text-align: center; ');
4545
await page.click('#make-call');
4646

4747
await waitForResponse({ expectErrors: true });
48-
expect(await page.evaluate(() => document.querySelector<HTMLHeadingElement>('#is-valid').innerText)).toBe('false');
48+
expect(await page.evaluate(() => document.querySelector<HTMLHeadingElement>('#is-valid')?.innerText)).toBe('false');
4949
expect(
50-
await page.evaluate(() => document.querySelector<HTMLUListElement>('#errors').childElementCount)
50+
await page.evaluate(() => document.querySelector<HTMLUListElement>('#errors')?.childElementCount)
5151
).toBeGreaterThan(0);
5252
});
5353

@@ -57,8 +57,18 @@ it('Includes warnings present in the response on the result when options specify
5757
await page.click('#make-call');
5858

5959
await waitForResponse({ expectWarnings: true });
60-
expect(await page.evaluate(() => document.querySelector<HTMLHeadingElement>('#is-valid').innerText)).toBe('true');
60+
expect(await page.evaluate(() => document.querySelector<HTMLHeadingElement>('#is-valid')?.innerText)).toBe('true');
6161
expect(
62-
await page.evaluate(() => document.querySelector<HTMLUListElement>('#warnings').childElementCount)
62+
await page.evaluate(() => document.querySelector<HTMLUListElement>('#warnings')?.childElementCount)
6363
).toBeGreaterThan(0);
6464
});
65+
66+
it('Does not include warnings on the result when warnings aren’t enabled', async () => {
67+
await page.type('#custom-css', '.foo { font-family: Georgia; }');
68+
await page.select('#warning-level', '0');
69+
await page.click('#make-call');
70+
71+
await waitForResponse();
72+
expect(await page.evaluate(() => document.querySelector<HTMLHeadingElement>('#is-valid')?.innerText)).toBe('true');
73+
expect(await page.evaluate(() => document.querySelector<HTMLUListElement>('#warnings')?.childElementCount)).toBe(0);
74+
});

test/puppeteer/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
"outDir": "./dist",
1111
"removeComments": true,
1212
"resolveJsonModule": true,
13-
"rootDir": "src",
13+
"rootDirs": ["src", "test"],
1414
"sourceMap": true,
1515
"strict": true,
1616
"strictNullChecks": true,
1717
"target": "es6"
1818
},
19-
"include": ["src/**/*"],
19+
"include": ["src/**/*", "test/*.ts"],
2020
"exclude": ["node_modules"]
2121
}

tsconfig.base.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"declarationMap": true,
5+
"esModuleInterop": true,
6+
"moduleResolution": "node",
7+
"noImplicitAny": true,
8+
"noUnusedLocals": true,
9+
"removeComments": true,
10+
"resolveJsonModule": true,
11+
"rootDirs": ["src", "test"],
12+
"sourceMap": true,
13+
"strict": true,
14+
"strictNullChecks": true
15+
},
16+
"include": ["src/**/*", "test/*", "./*.ts"],
17+
"exclude": ["node_modules"]
18+
}

tsconfig.build.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"module": "CommonJS",
5+
"outDir": "./dist/",
6+
"target": "ES2015"
7+
},
8+
"exclude": ["test/*", "./*.ts"]
9+
}

tsconfig.eslint.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"extends": "./tsconfig.json",
2+
"extends": "./tsconfig.base.json",
33
"include": ["test/**/*"]
44
}

tsconfig.json

+4-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
{
2+
"extends": "./tsconfig.base.json",
23
"compilerOptions": {
3-
"declaration": true,
4-
"declarationMap": true,
5-
"esModuleInterop": true,
6-
"module": "commonjs",
7-
"moduleResolution": "node",
8-
"noImplicitAny": true,
9-
"noUnusedLocals": true,
10-
"outDir": "./dist",
11-
"removeComments": true,
12-
"resolveJsonModule": true,
13-
"rootDir": "src",
14-
"sourceMap": true,
15-
"strict": true,
16-
"strictNullChecks": true,
17-
"target": "es6"
18-
},
19-
"include": ["src/**/*"],
20-
"exclude": ["node_modules"]
4+
"module": "CommonJS",
5+
"target": "ES2015"
6+
}
217
}

0 commit comments

Comments
 (0)