diff --git a/package.json b/package.json index 4f5650d..830665c 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,17 @@ { - "name": "distill-css", - "description": "PACKAGE_DESCRIPTION", + "name": "extract-css-core", + "description": "Extract all CSS from a given url, both server side and client side rendered.", "version": "0.1.0", "homepage": "https://www.projectwallace.com/oss", - "repository": "PACKAGE_REPOSITORY", - "issues": "PACKAGE_ISSUES", + "repository": "https://github.com/bartveneman/extract-css-core", + "issues": "https://github.com/bartveneman/extract-css-core/issues", "license": "MIT", "author": "Bart Veneman", "keywords": [ - "PACKAGE_KEYWORD" + "extract", + "css", + "scrape", + "get-css" ], "scripts": { "test": "xo && ava test" @@ -21,7 +24,25 @@ "node": ">=8.0" }, "xo": { - "prettier": true + "prettier": true, + "rules": { + "ava/no-skip-test": "warn" + } + }, + "prettier": { + "useTabs": true, + "semi": false, + "singleQuote": true, + "bracketSpacing": false, + "proseWrap": "always", + "overrides": [ + { + "files": "*.json", + "options": { + "useTabs": false + } + } + ] }, "devDependencies": { "ava": "^1.3.1", diff --git a/readme.md b/readme.md index f4ecfd1..b5a0f59 100644 --- a/readme.md +++ b/readme.md @@ -16,15 +16,24 @@ ### Problem -Existing packages like [get-css](https://github.com/cssstats/cssstats/tree/master/packages/get-css) look at a server-generated piece of HTML and get all the `` and ` - + + - -
+ +
- - - + + + - - + ReactDOM.render( + React.createElement(App, null), + document.querySelector('#app') + ) + + diff --git a/test/fixture.css b/test/fixture.css index b82e370..1fa6a8f 100644 --- a/test/fixture.css +++ b/test/fixture.css @@ -1,3 +1,3 @@ body { - color: teal; + color: teal; } diff --git a/test/index.js b/test/index.js index 752bff2..32ccd04 100644 --- a/test/index.js +++ b/test/index.js @@ -1,154 +1,154 @@ -const test = require("ava"); -const createTestServer = require("create-test-server"); -const { readFileSync } = require("fs"); -const { resolve } = require("path"); -const extractCss = require(".."); +const test = require('ava') +const createTestServer = require('create-test-server') +const {readFileSync} = require('fs') +const {resolve} = require('path') +const extractCss = require('..') -let server; -const expected = readFileSync(resolve(__dirname, "fixture.css"), "utf8"); +let server +const expected = readFileSync(resolve(__dirname, 'fixture.css'), 'utf8') test.before(async () => { - server = await createTestServer(); + server = await createTestServer() - server.get("/fixture.css", (req, res) => { - res.send(expected); - }); -}); + server.get('/fixture.css', (req, res) => { + res.send(expected) + }) +}) test.after(async () => { - await server.close(); -}); + await server.close() +}) -test("it fetches css from a page with CSS in a server generated inside the ", async t => { - const url = "/server-link-head"; - server.get(url, (req, res) => { - res.send(` +test('it fetches css from a page with CSS in a server generated inside the ', async t => { + const url = '/server-link-head' + server.get(url, (req, res) => { + res.send(` - `); - }); + `) + }) - const actual = await extractCss(server.url + url); + const actual = await extractCss(server.url + url) - t.is(actual, expected); -}); + t.is(actual, expected) +}) -test("it fetches css from a page with CSS in server generated - `); - }); - - const actual = await extractCss(server.url + url); - - t.is(actual, expected.trim()); -}); - -test("it finds JS generated CSS", async t => { - const path = "/js-generated-link"; - const cssInJsExampleHtml = readFileSync( - resolve(__dirname, "js-create-link-element.html"), - "utf8" - ); - - server.get(path, (req, res) => { - res.send(cssInJsExampleHtml); - }); - - const actual = await extractCss(server.url + path); - - t.is(actual, expected); -}); - -test("it finds JS generated - - -

Title

+ + + + +

Title

- - + // Client generated link + var style = document.createElement('link') + style.href = 'fixture.css' + style.rel = 'stylesheet' + document.head.appendChild(style) + + diff --git a/test/snapshots/index.js.md b/test/snapshots/index.js.md index 14c1072..0a7cf0c 100644 --- a/test/snapshots/index.js.md +++ b/test/snapshots/index.js.md @@ -4,30 +4,30 @@ The actual snapshot is saved in `index.js.snap`. Generated by [AVA](https://ava.li). -## it combines server generated and