Skip to content

Commit

Permalink
remove mocks and use real request for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseykulikov committed Sep 11, 2019
1 parent 781a81d commit f655e24
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 299 deletions.
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ npm link lighthouse-plugin-field-performance # add symlink to test the plugin lo

npm run mobile-run https://www.apple.com/ # test plugin with a real PSI API response
npm run desktop-run https://www.google.com/
npm run mock-run # test UI with mock data
```

`lighthouse-plugin-field-performance` folder is made of symlinks for a simple local testing.
Expand Down
126 changes: 0 additions & 126 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@
},
"devDependencies": {
"@types/node": "10",
"@types/sinon": "^7.0.13",
"ava": "^2.3.0",
"lighthouse": "^5.2.0",
"prettier": "^1.18.2",
"sinon": "^7.4.2",
"typescript": "^3.6.3"
}
}
6 changes: 0 additions & 6 deletions test/fixtures/load-experience-not-in-crux.json

This file was deleted.

96 changes: 0 additions & 96 deletions test/fixtures/load-experience.json

This file was deleted.

17 changes: 4 additions & 13 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
const { serial } = require('ava')
const { readFileSync } = require('fs')
const { join } = require('path')
const sinon = require('sinon')
const { runLighthouse } = require('lighthouse/lighthouse-cli/run')
const psi = require('../src/utils/run-psi')
const loadExperienceInCrUX = require('./fixtures/load-experience.json')
const loadExperienceNotInCrUX = require('./fixtures/load-experience-not-in-crux.json')

const lhOptions = {
output: ['json'],
outputPath: './results/test-results.json',
chromeFlags: '--headless --enable-logging --no-sandbox',
onlyCategories: ['lighthouse-plugin-field-performance'],
plugins: ['lighthouse-plugin-field-performance']
}

Expand All @@ -19,16 +16,10 @@ const getTestResults = resName => {
return JSON.parse(readFileSync(join(__dirname, '../results', resName), 'utf8'))
}

sinon
.stub(psi, 'runPsi')
.onFirstCall()
.returns(Promise.resolve(loadExperienceInCrUX))
.onSecondCall()
.returns(Promise.resolve(loadExperienceNotInCrUX))

serial('Measure field perf for site in CruX', async t => {
const resName = 'in-field.json'
await runLighthouse('https://google.com/', { ...lhOptions, outputPath: `./results/${resName}` })
await runLighthouse('https://example.com/', { ...lhOptions, outputPath: `./results/${resName}` })
// FIXME: don't snapshot numeric values
const { audits, categories } = getTestResults(resName)
t.snapshot(audits['field-fcp'])
t.snapshot(audits['field-fid'])
Expand All @@ -39,7 +30,7 @@ serial('Measure field perf for site in CruX', async t => {

serial('Measure field perf for site site not in CruX', async t => {
const resName = 'not-in-field.json'
await runLighthouse('https://example.com/', { ...lhOptions, outputPath: `./results/${resName}` })
await runLighthouse('https://alekseykulikov.com/', { ...lhOptions, outputPath: `./results/${resName}` })

const { audits, categories } = getTestResults(resName)
t.snapshot(audits['field-fcp'])
Expand Down
Loading

0 comments on commit f655e24

Please sign in to comment.