Skip to content

Commit

Permalink
Merge 785ee76 into 9387de5
Browse files Browse the repository at this point in the history
  • Loading branch information
mouafa committed Sep 3, 2018
2 parents 9387de5 + 785ee76 commit fc22f75
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
24 changes: 21 additions & 3 deletions src/lib/check.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
const Listr = require('listr')

const Shot = require('./shot')
const Page = require('./page')
const log = require('./log')
const { arrayArg } = require('./util')

// async function check(urls) {
// urls = arrayArg(urls)
// return Promise.all(urls.map(checkPage))
// }

async function check(urls) {
urls = arrayArg(urls)
return Promise.all(urls.map(checkPage))
const tasks = urls.map(url => {
return {
title: url,
task() {
return checkPage(url)
}
}
})

return new Listr(tasks, { concurrent: true, exitOnError: false }).run()
}

async function checkPage(url) {
const page = new Page(url)
await page.runTasks(verifier)
const tasks = page.getTasks(verifier)
return new Listr(tasks, { concurrent: true, exitOnError: false })
// await page.runTasks(verifier)
}

async function verifier([url, viewport, suffix]) {
const shot = new Shot(url, viewport, suffix)
const match = await shot.check()
log('match', match, url, suffix)
// log('match', match, url, suffix)
}

module.exports = {
Expand Down
17 changes: 12 additions & 5 deletions src/lib/page.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const Listr = require('listr')

const config = require('../config').getConfig()
const viewports = config.viewports

Expand All @@ -15,16 +17,21 @@ class Page {

getTasks(cb) {
return this.set.map(options => {
return function task() {
return cb(options)
return {
title: `${options[2]}`,
task() {
return cb(options)
}
}
})
}

runTasks(cb) {
const tasks = this.getTasks(cb)
const promises = tasks.map(async task => await task())
return Promise.all(promises)
const tasks = new Listr(this.getTasks(cb), { concurrent: true, exitOnError: false })

// const promises = tasks.map(async task => await task())
// return Promise.all(promises)
return tasks.run()
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/page.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ describe('Page | getTasks', () => {
const max = Object.keys(viewports).length
let count = 0
const tasks = page.getTasks(() => ++count)
expect(tasks).toEqual(expect.arrayContaining([expect.any(Function)]))
tasks.map(task => task())
expect(tasks).toEqual(expect.arrayContaining([{ task: expect.any(Function), title: expect.any(String) }]))
tasks.map(({ task }) => task())
expect(count).toEqual(max)
})

it('should generate right tasks | with right args', () => {
const page = new Page(url)
let cb = jest.fn()
const tasks = page.getTasks(cb)
expect(tasks).toEqual(expect.arrayContaining([expect.any(Function)]))
tasks[0]()
expect(tasks).toEqual(expect.arrayContaining([{ task: expect.any(Function), title: expect.any(String) }]))
tasks[0].task()
expect(cb).toHaveBeenCalledTimes(1)
expect(cb).toHaveBeenCalledWith(expect.arrayContaining(expectedSort[0]))
})
Expand Down
4 changes: 2 additions & 2 deletions testdrive.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
const firn = require('./')
const log = require('./src/lib/log')

const urls = ['https://smartfrog.com/de-de/shop']
const urls = ['https://smartfrog.com/de-de/shop', 'https://smartfrog.com/de-de/shop/products']
const config = {}

firn(urls[0], config)
firn(urls, config)
.then(e => {
log('👍 ALL GOOD')
})
Expand Down

0 comments on commit fc22f75

Please sign in to comment.