Skip to content
This repository has been archived by the owner on May 28, 2021. It is now read-only.

Commit

Permalink
update packages & add lighthouse test to CI & lint
Browse files Browse the repository at this point in the history
  • Loading branch information
LekoArts committed Jan 31, 2019
1 parent 5e02ee8 commit d7ae777
Show file tree
Hide file tree
Showing 6 changed files with 1,823 additions and 471 deletions.
81 changes: 49 additions & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ executors:
type: string
default: "10"
docker:
- image: circleci/node:<< parameters.image >>
environment:
TERM: xterm
- image: circleci/node:<< parameters.image >>
environment:
TERM: xterm

aliases:
e2e-executor: &e2e-executor
docker:
- image: cypress/base:8
environment:
TERM: xterm
- image: cypress/base:8
environment:
TERM: xterm

restore_cache: &restore_cache
restore_cache:
name: Restore Yarn Package Cache
keys:
- v{{ .Environment.versionCache }}-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}-{{ checksum ".circleci/config.yml" }}
- v{{ .Environment.versionCache }}-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}-{{ checksum ".circleci/config.yml" }}

install_node_modules: &install_node_modules
run:
Expand All @@ -32,7 +32,7 @@ aliases:
name: Save Yarn Package Cache
key: v{{ .Environment.versionCache }}-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}-{{ checksum ".circleci/config.yml" }}
paths:
- /home/circleci/.cache
- /home/circleci/.cache

store_results: &store_results
store_test_results:
Expand All @@ -48,36 +48,53 @@ jobs:
lint:
executor: node
steps:
- checkout
- <<: *restore_cache
- <<: *install_node_modules
- <<: *save_cache
- run:
name: Run ESLint
command: yarn lint:ci
- <<: *store_results
- <<: *store_results_artifacts
- checkout
- <<: *restore_cache
- <<: *install_node_modules
- <<: *save_cache
- run:
name: Run ESLint
command: yarn lint:ci
- <<: *store_results
- <<: *store_results_artifacts

e2e_cypress:
<<: *e2e-executor
steps:
- checkout
- <<: *restore_cache
- <<: *install_node_modules
- <<: *save_cache
- run:
name: Run E2E tests
command: yarn test:e2e:ci
- <<: *store_results
- <<: *store_results_artifacts
- store_artifacts:
path: cypress/videos
- store_artifacts:
path: cypress/screenshots
- checkout
- <<: *restore_cache
- <<: *install_node_modules
- <<: *save_cache
- run:
name: Run E2E tests
command: yarn test:e2e:ci
- <<: *store_results
- <<: *store_results_artifacts
- store_artifacts:
path: cypress/videos
- store_artifacts:
path: cypress/screenshots

lighthouse:
executor:
name: node
image: "10-browsers"
steps:
- checkout
- <<: *restore_cache
- <<: *install_node_modules
- <<: *save_cache
- run:
name: Build Gatsby site
command: yarn build
- run:
name: Test Lighthouse scores
command: yarn test:lighthouse

workflows:
version: 2
lint-test:
jobs:
- lint
- e2e_cypress
- lint
- e2e_cypress
- lighthouse
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</strong>
</p>

***
---

## Features

Expand All @@ -76,6 +76,6 @@

## License

Only for educational purposes! You are **not** allowed to use this site publicly and/or commercially.
Only for educational purposes! You are **not** allowed to use this site publicly and/or commercially.

You are **not** permitted to use, modify, or share the software for any purpose other than for private educational purposes.
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
modulePathIgnorePatterns: ['<rootDir>/.cache', '<rootDir>/node_modules'],
}
51 changes: 51 additions & 0 deletions lighthouse.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const lighthouse = require('lighthouse')
const chromeLauncher = require('chrome-launcher')
const Table = require('cli-table')

const table = new Table()

const output = scores => {
Object.keys(scores).forEach(category => {
table.push([category, Math.round(scores[category] * 100)])
})
return table.toString()
}

const launchChromeAndRunLighthouse = async (url, opts = {}, config = null) => {
const chrome = await chromeLauncher.launch({ chromeFlags: opts.chromeFlags })
opts.port = chrome.port

const results = await lighthouse(url, opts, config)
await chrome.kill()

return results
}

let scores

beforeAll(async () => {
const { lhr } = await launchChromeAndRunLighthouse('http://localhost:9000')
scores = Object.keys(lhr.categories).reduce((merged, category) => {
merged[category] = lhr.categories[category].score
return merged
}, {})
}, 10000)

describe(`Lighthouse Audit`, () => {
it('Performance score above 92', () => {
expect(scores.performance).toBeGreaterThanOrEqual(0.93)
})
it('Accessibility score above 92', () => {
expect(scores.accessibility).toBeGreaterThanOrEqual(0.93)
})
it('Best Practices score above 92', () => {
expect(scores['best-practices']).toBeGreaterThanOrEqual(0.93)
})
it('SEO score above 92', () => {
expect(scores.seo).toBeGreaterThanOrEqual(0.93)
})
})

afterAll(() => {
console.log(output(scores))
})
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
"devDependencies": {
"babel-eslint": "^10.0.1",
"babel-preset-env": "^1.7.0",
"chrome-launcher": "^0.10.5",
"cli-table": "^0.3.1",
"cypress": "^3.1.4",
"cypress-testing-library": "^2.3.5",
"dotenv": "^6.2.0",
Expand All @@ -56,6 +58,8 @@
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-prettier": "^3.0.1",
"eslint-plugin-react": "^7.12.3",
"jest": "^24.0.0",
"lighthouse": "^4.1.0",
"prettier": "^1.15.3",
"start-server-and-test": "^1.7.11"
},
Expand All @@ -75,11 +79,14 @@
"cy:open": "cypress open",
"cy:run": "cypress run",
"cy:run:ci": "cypress run --reporter junit --reporter-options 'mochaFile=results/cypress/result.xml'",
"format": "prettier \"**/*.{md,mdx,yml} \" --write",
"lint": "eslint . --ext .js,.jsx --ignore-path .gitignore",
"lint:fix": "eslint . --ext .js,.jsx --fix --ignore-path .gitignore",
"lint:ci": "yarn lint --format junit -o results/eslint/result.xml",
"test": "jest",
"test:e2e:dev": "start-server-and-test dev http://localhost:8000 cy:open",
"test:e2e:run": "start-server-and-test develop http://localhost:8000 cy:run",
"test:e2e:ci": "start-server-and-test develop http://localhost:8000 cy:run:ci"
"test:e2e:ci": "start-server-and-test develop http://localhost:8000 cy:run:ci",
"test:lighthouse": "start-server-and-test serve http://localhost:9000 test"
}
}
Loading

0 comments on commit d7ae777

Please sign in to comment.