Skip to content

Commit

Permalink
await
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Mar 13, 2022
1 parent 014fd80 commit 8d1ba76
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions test/helpers/compare-svg-2-png-helper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const fs = require('fs');
const fs = require('fs').promises;
const path = require('path');
const puppeteer = require('puppeteer');
const looksSame = require('looks-same');
Expand All @@ -16,7 +16,7 @@ const convertSvg2Png = require('./convert-svg-2-png.js');
* @param {Function} done Callback
*/
module.exports = async(svg, png, expected, diff, done) => {
fs.mkdirSync(path.dirname(png), { recursive: true });
await fs.mkdir(path.dirname(png), { recursive: true });
let browser;

try {
Expand Down
8 changes: 4 additions & 4 deletions test/helpers/write-file.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const fs = require('fs');
const fs = require('fs').promises;
const path = require('path');

/**
Expand All @@ -10,10 +10,10 @@ const path = require('path');
* @param {string} content Content
* @returns {string} File
*/
module.exports = (file, content) => {
module.exports = async(file, content) => {
try {
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, content);
await fs.mkdir(path.dirname(file), { recursive: true });
await fs.writeFile(file, content);
return file;
} catch {
return null;
Expand Down
10 changes: 5 additions & 5 deletions test/svg-sprite/alignment/center.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe(`svg-sprite: with centered alignment and ${align.length} SVG files`, ()
data.css = '../sprite.centered.css';

const out = mustache.render(previewTemplate, data);
const preview = writeFile(path.join(tmpPath, 'css/html/css.vertical.centered.html'), out);
const preview = await writeFile(path.join(tmpPath, 'css/html/css.vertical.centered.html'), out);

await expect(preview).toBeVisuallyCorrectAsHTML(path.join(paths.expectations, 'png/css.vertical.centered.html.png'));
});
Expand Down Expand Up @@ -122,12 +122,12 @@ describe(`svg-sprite: with centered alignment and ${align.length} SVG files`, ()

const scssText = sass.renderSync({ file: path.join(tmpPath, 'css/sprite.centered.scss') });

writeFile(path.join(tmpPath, 'css/sprite.centered.scss.css'), scssText.css);
await writeFile(path.join(tmpPath, 'css/sprite.centered.scss.css'), scssText.css);

data.css = '../sprite.centered.scss.css';

const out = mustache.render(previewTemplate, data);
const preview = writeFile(path.join(tmpPath, 'css/html/scss.horizontal.centered.html'), out);
const preview = await writeFile(path.join(tmpPath, 'css/html/scss.horizontal.centered.html'), out);

await expect(preview).toBeVisuallyCorrectAsHTML(path.join(paths.expectations, '/png/css.horizontal.centered.html.png'));
});
Expand Down Expand Up @@ -184,12 +184,12 @@ describe(`svg-sprite: with centered alignment and ${align.length} SVG files`, ()

const output = await asyncRenderers.less(lessText, {});

writeFile(path.join(tmpPath, 'css/sprite.centered.less.css'), output.css);
await writeFile(path.join(tmpPath, 'css/sprite.centered.less.css'), output.css);

data.css = '../sprite.centered.less.css';

const out = mustache.render(previewTemplate, data);
const preview = writeFile(path.join(tmpPath, 'css/html/less.packed.centered.html'), out);
const preview = await writeFile(path.join(tmpPath, 'css/html/less.packed.centered.html'), out);

await expect(preview).toBeVisuallyCorrectAsHTML(path.join(paths.expectations, '/png/css.packed.aligned.html.png'));
});
Expand Down
6 changes: 3 additions & 3 deletions test/svg-sprite/alignment/mixed.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe(`svg-sprite: with mixed alignment and ${align.length} SVG files`, () =>
data.css = '../sprite.mixed.css';

const out = mustache.render(previewTemplate, data);
const preview = writeFile(path.join(tmpPath, 'view/html/css.vertical.mixed.html'), out);
const preview = await writeFile(path.join(tmpPath, 'view/html/css.vertical.mixed.html'), out);

await expect(preview).toBeVisuallyCorrectAsHTML(
path.join(paths.expectations, '/png/css.vertical.mixed.html.png')
Expand Down Expand Up @@ -126,12 +126,12 @@ describe(`svg-sprite: with mixed alignment and ${align.length} SVG files`, () =>
expect.hasAssertions();

const scssText = sass.renderSync({ file: path.join(tmpPath, 'view/sprite.mixed.scss') });
writeFile(path.join(tmpPath, 'view/sprite.mixed.scss.css'), scssText.css);
await writeFile(path.join(tmpPath, 'view/sprite.mixed.scss.css'), scssText.css);

data.css = '../sprite.mixed.scss.css';

const out = mustache.render(previewTemplate, data);
const preview = writeFile(path.join(tmpPath, 'view/html/scss.horizontal.mixed.html'), out);
const preview = await writeFile(path.join(tmpPath, 'view/html/scss.horizontal.mixed.html'), out);

await expect(preview).toBeVisuallyCorrectAsHTML(path.join(paths.expectations, 'png/css.horizontal.mixed.html.png'));
});
Expand Down
14 changes: 7 additions & 7 deletions test/svg-sprite/minimal-configuration/modes/css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('testing minimal config', () => {

data.css = `../sprite${testConfig.namespace}.css`;
const out = mustache.render(previewTemplate, data);
const preview = writeFile(path.join(tmpPath, `css/html/css${testConfig.namespace}.html`), out);
const preview = await writeFile(path.join(tmpPath, `css/html/css${testConfig.namespace}.html`), out);

await expect(preview).toBeVisuallyCorrectAsHTML(path.join(paths.expectations, `png/css.html${testConfig.namespace}.png`));
});
Expand All @@ -139,12 +139,12 @@ describe('testing minimal config', () => {
expect.hasAssertions();

const scssText = sass.renderSync({ file: path.join(tmpPath, `css/sprite${testConfig.namespace}.scss`) });
writeFile(path.join(tmpPath, `css/sprite${testConfig.namespace}.scss.css`), scssText.css);
await writeFile(path.join(tmpPath, `css/sprite${testConfig.namespace}.scss.css`), scssText.css);

data.css = `../sprite${testConfig.namespace}.scss.css`;

const out = mustache.render(previewTemplate, data);
const preview = writeFile(path.join(tmpPath, `css/html/scss${testConfig.namespace}.html`), out);
const preview = await writeFile(path.join(tmpPath, `css/html/scss${testConfig.namespace}.html`), out);

await expect(preview).toBeVisuallyCorrectAsHTML(path.join(paths.expectations, `png/css.html${testConfig.namespace}.png`));
});
Expand All @@ -157,12 +157,12 @@ describe('testing minimal config', () => {
const lessText = fs.readFileSync(lessFile, 'utf-8');

const output = await asyncRenderers.less(lessText, {});
writeFile(path.join(tmpPath, `css/sprite${testConfig.namespace}.less.css`), output.css);
await writeFile(path.join(tmpPath, `css/sprite${testConfig.namespace}.less.css`), output.css);

data.css = `../sprite${testConfig.namespace}.less.css`;

const out = mustache.render(previewTemplate, data);
const preview = writeFile(path.join(tmpPath, `css/html/less${testConfig.namespace}.html`), out);
const preview = await writeFile(path.join(tmpPath, `css/html/less${testConfig.namespace}.html`), out);

await expect(preview).toBeVisuallyCorrectAsHTML(path.join(paths.expectations, `png/css.html${testConfig.namespace}.png`));
});
Expand All @@ -176,12 +176,12 @@ describe('testing minimal config', () => {

const output = await asyncRenderers.stylus(stylusText, {});

writeFile(path.join(tmpPath, `css/sprite${testConfig.namespace}.styl.css`), output);
await writeFile(path.join(tmpPath, `css/sprite${testConfig.namespace}.styl.css`), output);

data.css = `../sprite${testConfig.namespace}.styl.css`;

const out = mustache.render(previewTemplate, data);
const preview = writeFile(path.join(tmpPath, `css/html/styl${testConfig.namespace}.html`), out);
const preview = await writeFile(path.join(tmpPath, `css/html/styl${testConfig.namespace}.html`), out);

await expect(preview).toBeVisuallyCorrectAsHTML(path.join(paths.expectations, `png/css.html${testConfig.namespace}.png`));
});
Expand Down
2 changes: 1 addition & 1 deletion test/svg-sprite/minimal-configuration/modes/symbol.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe.each`
data.css = '../sprite.css';
const previewTemplate = fs.readFileSync(path.join(__dirname, '../../../tmpl/symbol.html'), 'utf-8');
const out = mustache.render(previewTemplate, data);
const preview = writeFile(path.join(tmpPath, 'symbol/html/symbol.html'), out);
const preview = await writeFile(path.join(tmpPath, 'symbol/html/symbol.html'), out);

await expect(preview).toBeVisuallyCorrectAsHTML(path.join(paths.expectations, `png/symbol.html${testConfig.namespace}.png`));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ describe('svg-sprite: with «view» mode, packed layout and LESS render type', (
const lessFile = path.join(tmpPath, 'view/sprite.mixed.less');
const lessText = fs.readFileSync(lessFile, 'utf-8');
const output = await asyncRenderers.less(lessText, {});
writeFile(path.join(tmpPath, 'view/sprite.mixed.less.css'), output.css);
await writeFile(path.join(tmpPath, 'view/sprite.mixed.less.css'), output.css);

data.css = '../sprite.mixed.less.css';

const out = mustache.render(previewTemplate, data);
const preview = writeFile(path.join(tmpPath, 'view/html/less.packed.mixed.html'), out);
const preview = await writeFile(path.join(tmpPath, 'view/html/less.packed.mixed.html'), out);

await expect(preview).toBeVisuallyCorrectAsHTML(path.join(paths.expectations, '/png/css.packed.aligned.html.png'));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe.each`
data.css = '../sprite.css';
const previewTemplate = fs.readFileSync(path.join(__dirname, '../../../tmpl/view.html'), 'utf-8');
const out = mustache.render(previewTemplate, data);
const preview = writeFile(path.join(tmpPath, 'view/html/view.html'), out);
const preview = await writeFile(path.join(tmpPath, 'view/html/view.html'), out);

await expect(preview).toBeVisuallyCorrectAsHTML(path.join(paths.expectations, `png/view.html${testConfig.namespace}.png`));
});
Expand Down

0 comments on commit 8d1ba76

Please sign in to comment.