TypeError:“listener”参数必须是一个函数。在节点JS中使用npm pixelmatch

时间:2018-05-19 16:06:08

标签: javascript node.js npm mocha chai

我正在使用带有mocha和chai的nodeJS,重要的是像素匹配。

我已截屏并备份。 我想比较它们并使用像素匹配产生差异的差异文件夹。 我一直在收到错误。

 img1 = fs.createReadStream(screenshot_path).pipe(new PNG()).on('parsed', doneReading())

错误是指.66:

const compareScreenshots = async (path) => {
     const diff_path = "./build/diff/" + path + ".diff.png"
     const screenshot_path = "./build/" + path + ".png"
     const backup_path = "./backup/" + path +".png"
    let img1, img2, filesRead = 0;

let doneReading = async function(){
    if(++filesRead < 2) return;

    var diff = new PNG({width: img1.width, height: img2.height});

    var numDiffPixels = pixelmatch(img1.data, img2.data, diff.data, img1.width, img1.height, {threshold: 0.1})

    diff.pack().pipe(fs.createWriteStream(diff_path));

    expect(numDiffPixels).to.equal(0) }

 img1 = fs.createReadStream(screenshot_path).pipe(new PNG()).on('parsed', doneReading())
 img2 = fs.createReadStream(backup_path).pipe(new PNG()).on('parsed', doneReading())
}

以下是我的比较截图代码:

let page_title = await page.$eval('title', page => page.textContent.replace(/ /g,''))

输入'path'是:

.dataLabel span:last-child{
border-right: none;
}

0 个答案:

没有答案