From 709f74665e1e2be59d7451cff73265f04826811e Mon Sep 17 00:00:00 2001 From: Bernhard Behrendt Date: Thu, 21 Jan 2021 11:39:20 +0100 Subject: [PATCH 1/4] #23 and #24 add interaction (menu icon) and exit browser --- index.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 8410d35..6839e06 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ const PAGE = { ICON_INPUT: '.menuList2.menuList3 .file input[type="file"]', FIRST_ICON_BOX: '#set0 .miBox:not(.mi-selected)', REMOVE_SET_BUTTON: '.menuList2.menuList3 li:last-child button', + OPEN_FEATURES_MENU: '#setH0 > button', SELECT_ALL_BUTTON: 'button[ng-click="selectAllNone($index, true)"]', GENERATE_LINK: 'a[href="#/select/font"]', GLYPH_SET: '#glyphSet0', @@ -91,7 +92,7 @@ const checkDuplicateName = ({ selectionPath, icons, names }, forceOverride) => { } }; -async function pipeline(options = {}) { +const pipeline = async (options = {})=> { try { const { icons, @@ -153,7 +154,14 @@ async function pipeline(options = {}) { const iconPaths = icons.map(getAbsolutePath); await iconInput.uploadFile(...iconPaths); await page.waitForSelector(PAGE.FIRST_ICON_BOX); - await page.click(PAGE.SELECT_ALL_BUTTON); + + // neccesarry in some scenarios + try { + await page.click(PAGE.SELECT_ALL_BUTTON); + } catch (e) { + + } + logger('Uploaded and selected all new icons'); await page.click(PAGE.GENERATE_LINK); await page.waitForSelector(PAGE.GLYPH_SET); @@ -163,20 +171,20 @@ async function pipeline(options = {}) { await sleep(1000); await page.evaluate(names => { const request = indexedDB.open('IDBWrapper-storage', 1); - request.onsuccess = function() { + request.onsuccess = () => { const db = request.result; const tx = db.transaction('storage', 'readwrite'); const store = tx.objectStore('storage'); const keys = store.getAllKeys(); - keys.onsuccess = function() { + keys.onsuccess = () => { let timestamp; - keys.result.forEach(function(key) { + keys.result.forEach((key) => { if (typeof key === 'number') { timestamp = key; } }); const main = store.get(timestamp); - main.onsuccess = function() { + main.onsuccess = () => { const data = main.result; for (let i = 0; i < names.length; i++) { data.obj.iconSets[0].selection[i].name = names[i]; @@ -205,7 +213,7 @@ async function pipeline(options = {}) { logger('Successfully downloaded, going to unzip it.'); await page.close(); // unzip stage - extract(zipPath, { dir: outputDir }, async err => { + extract(zipPath, {dir: outputDir}, async err => { if (err) { throw err; } @@ -215,9 +223,12 @@ async function pipeline(options = {}) { whenFinished({ outputDir }); } }); + + await browser.close(); + } catch (error) { console.error(error); } -} +}; module.exports = pipeline; From 4d0a3d2b894a0767478b035aade1528d7ae8bec2 Mon Sep 17 00:00:00 2001 From: Bernhard Behrendt Date: Thu, 21 Jan 2021 11:41:47 +0100 Subject: [PATCH 2/4] dependency upgrades (tests passing) --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 74d6c6d..cc34f62 100644 --- a/package.json +++ b/package.json @@ -17,12 +17,12 @@ "author": "", "license": "ISC", "dependencies": { - "extract-zip": "^1.6.6", - "fs-extra": "^4.0.2", - "yargs": "^10.0.3", - "puppeteer": "2.0.0" + "extract-zip": "^2.0.1", + "fs-extra": "^9.1.0", + "yargs": "^16.2.0", + "puppeteer": "5.5.0" }, "devDependencies": { - "eslint": "^4.10.0" + "eslint": "^7.18.0" } } From d2174eaedc17c2bc8e57d32aecd40c02974b2a66 Mon Sep 17 00:00:00 2001 From: Bernhard Date: Thu, 21 Jan 2021 11:42:19 +0100 Subject: [PATCH 3/4] version update (1.3.3) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cc34f62..d065711 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "icomoon-cli", - "version": "1.3.2", + "version": "1.3.3", "description": "", "main": "index.js", "bin": { From 32c6cd073e9ded63fb380cd6f6a85a23da8c83cf Mon Sep 17 00:00:00 2001 From: Bernhard Behrendt Date: Thu, 21 Jan 2021 12:07:38 +0100 Subject: [PATCH 4/4] #23 #24 false positive tests --- index.js | 42 +++++++++++++++++++----------------------- index.test.js | 8 +++++--- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/index.js b/index.js index 6839e06..5ea331a 100644 --- a/index.js +++ b/index.js @@ -67,7 +67,7 @@ const checkDownload = dest => new Promise((resolve, reject) => { }, interval); }); -const checkDuplicateName = ({ selectionPath, icons, names }, forceOverride) => { +const checkDuplicateName = ({selectionPath, icons, names}, forceOverride) => { const iconNames = icons.map((icon, index) => { if (names[index]) { return names[index]; @@ -76,9 +76,9 @@ const checkDuplicateName = ({ selectionPath, icons, names }, forceOverride) => { }); const duplicates = []; const selection = fs.readJSONSync(selectionPath); - selection.icons.forEach(({ properties }, index) => { + selection.icons.forEach(({properties}, index) => { if (iconNames.includes(properties.name)) { - duplicates.push({ name: properties.name, index }); + duplicates.push({name: properties.name, index}); } }); if (!duplicates.length) { @@ -86,13 +86,13 @@ const checkDuplicateName = ({ selectionPath, icons, names }, forceOverride) => { } if (forceOverride) { selection.icons = selection.icons.filter((icon, index) => !duplicates.some(d => d.index === index)); - fs.writeJSONSync(selectionPath, selection, { spaces: 2 }); + fs.writeJSONSync(selectionPath, selection, {spaces: 2}); } else { throw new Error(`Found duplicate icon names: ${duplicates.map(d => d.name).join(',')}`); } }; -const pipeline = async (options = {})=> { +async function pipeline(options = {}) { try { const { icons, @@ -107,7 +107,7 @@ const pipeline = async (options = {})=> { logger('Preparing...'); if (!icons || !icons.length) { if (whenFinished) { - whenFinished({ outputDir }); + whenFinished({outputDir}); } return logger('No new icons found.'); } @@ -123,7 +123,7 @@ const pipeline = async (options = {})=> { await fs.remove(outputDir); await fs.ensureDir(outputDir); - const browser = await puppeteer.launch({ headless: !visible }); + const browser = await puppeteer.launch({headless: !visible}); logger('Started a new chrome instance, going to load icomoon.io.'); const page = await (await browser).newPage(); await page._client.send('Page.setDownloadBehavior', { @@ -139,13 +139,13 @@ const pipeline = async (options = {})=> { const importInput = await page.waitForSelector(PAGE.IMPORT_SELECTION_INPUT); await importInput.uploadFile(absoluteSelectionPath); - await page.waitForSelector(PAGE.OVERLAY_CONFIRM, { visible: true }); + await page.waitForSelector(PAGE.OVERLAY_CONFIRM, {visible: true}); await page.click(PAGE.OVERLAY_CONFIRM); const selection = fs.readJSONSync(selectionPath); if (selection.icons.length === 0) { logger('Selection icons is empty, going to create an empty set'); await page.click(PAGE.MAIN_MENU_BUTTON); - await page.waitForSelector(PAGE.NEW_SET_BUTTON, { visible: true }); + await page.waitForSelector(PAGE.NEW_SET_BUTTON, {visible: true}); await page.click(PAGE.NEW_SET_BUTTON); } logger('Uploaded config, going to upload new icon files'); @@ -154,14 +154,10 @@ const pipeline = async (options = {})=> { const iconPaths = icons.map(getAbsolutePath); await iconInput.uploadFile(...iconPaths); await page.waitForSelector(PAGE.FIRST_ICON_BOX); - - // neccesarry in some scenarios - try { - await page.click(PAGE.SELECT_ALL_BUTTON); - } catch (e) { - - } - + await sleep(1000); + await page.click(PAGE.OPEN_FEATURES_MENU); + await sleep(1000); + await page.click(PAGE.SELECT_ALL_BUTTON); logger('Uploaded and selected all new icons'); await page.click(PAGE.GENERATE_LINK); await page.waitForSelector(PAGE.GLYPH_SET); @@ -171,20 +167,20 @@ const pipeline = async (options = {})=> { await sleep(1000); await page.evaluate(names => { const request = indexedDB.open('IDBWrapper-storage', 1); - request.onsuccess = () => { + request.onsuccess = function () { const db = request.result; const tx = db.transaction('storage', 'readwrite'); const store = tx.objectStore('storage'); const keys = store.getAllKeys(); - keys.onsuccess = () => { + keys.onsuccess = function () { let timestamp; - keys.result.forEach((key) => { + keys.result.forEach(function (key) { if (typeof key === 'number') { timestamp = key; } }); const main = store.get(timestamp); - main.onsuccess = () => { + main.onsuccess = function () { const data = main.result; for (let i = 0; i < names.length; i++) { data.obj.iconSets[0].selection[i].name = names[i]; @@ -220,7 +216,7 @@ const pipeline = async (options = {})=> { await fs.remove(zipPath); logger(`Finished. The output directory is ${outputDir}.`); if (whenFinished) { - whenFinished({ outputDir }); + whenFinished({outputDir}); } }); @@ -229,6 +225,6 @@ const pipeline = async (options = {})=> { } catch (error) { console.error(error); } -}; +} module.exports = pipeline; diff --git a/index.test.js b/index.test.js index 495debb..307d471 100644 --- a/index.test.js +++ b/index.test.js @@ -14,11 +14,12 @@ const runCase = (name, fn) => new Promise((resolve, reject) => { resolve(); } } + console.log(`\r\n============= Start test '${name}' =============`); fn(done); }); -(async function() { +(async function () { await runCase('test with selection file which already has icons', done => { const names = ['new1', 'new2']; pipeline({ @@ -26,7 +27,8 @@ const runCase = (name, fn) => new Promise((resolve, reject) => { names, selectionPath: 'test-assets/selection.json', forceOverride: true, - whenFinished (result) { + // visible: true, + whenFinished(result) { const newSelection = JSON.parse(fs.readFileSync(path.resolve(result.outputDir, 'selection.json'))); assert.deepEqual( newSelection.icons.slice(0, names.length).map(icon => icon.properties.name), @@ -44,7 +46,7 @@ const runCase = (name, fn) => new Promise((resolve, reject) => { names, selectionPath: 'test-assets/selection-empty.json', forceOverride: true, - whenFinished (result) { + whenFinished(result) { const newSelection = JSON.parse(fs.readFileSync(path.resolve(result.outputDir, 'selection.json'))); assert.deepEqual( newSelection.icons.map(icon => icon.properties.name),