Skip to content

Commit

Permalink
fix: use cli in tests and return imports of yfm assets
Browse files Browse the repository at this point in the history
  • Loading branch information
yndx-birman committed Nov 21, 2023
1 parent d5d9453 commit c941916
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {dirname, join, resolve} from 'path';
import {resolve} from 'path';
import {execSync} from 'child_process';

import {toMatchImageSnapshot} from 'jest-image-snapshot';
import {fromPath} from 'pdf2pic';
import puppeteer from 'puppeteer';
import {Browser} from 'puppeteer-core';

import {generatePdf} from '../src';

expect.extend({toMatchImageSnapshot});

describe('integration', () => {
Expand All @@ -26,10 +25,7 @@ describe('integration', () => {
// @ts-ignore
browser = await puppeteer.launch({headless: true});

await generatePdf({
singlePagePath: join(dirname(pdfFile), 'single-page.json'),
browser,
});
execSync('node build/cmd/index.js -i integration-output');
});

it('works', async () => {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
],
"scripts": {
"build": "webpack",
"start": "node build/index.js",
"lint:js": "eslint --ext .js,.jsx,.ts,.tsx .",
"lint": "npm run lint:js",
"binary": "pkg .",
"test": "npm run integration:prepare && jest",
"test": "npm run build && npm run integration:prepare && jest",
"integration:clean": "rm -rf ./integration-output",
"integration:build": "npx -y --legacy-peer-deps -- @diplodoc/cli -i ./integration -o ./integration-output --single-page",
"integration:prepare": "npm run integration:clean && npm run integration:build"
Expand Down
22 changes: 9 additions & 13 deletions src/generate/utils.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import {readFileSync} from 'fs';
import {join} from 'path';

import {SINGLE_PAGE_DATA_FILENAME} from './constants';

export function generatePdfStaticMarkup(html: string) {
const yfmStylesPath = require.resolve('@diplodoc/transform/dist/css/yfm.css');
const yfmStyles = readFileSync(yfmStylesPath, 'utf-8');

const yfmPrintStylesPath = require.resolve('@diplodoc/transform/dist/css/print.css');
const yfmPrintStyles = readFileSync(yfmPrintStylesPath, 'utf-8');

const yfmPrintJSPath = require.resolve('@diplodoc/transform/dist/js/print.js');
const yfmPrintJS = readFileSync(yfmPrintJSPath, 'utf-8');

const yfmJSPath = require.resolve('@diplodoc/transform/dist/js/yfm.js');
const yfmJS = readFileSync(yfmJSPath, 'utf-8');
// @ts-ignore
import yfmStyles from '@diplodoc/transform/dist/css/yfm.css';
// @ts-ignore
import yfmPrintStyles from '@diplodoc/transform/dist/css/print.css';
// @ts-ignore
import yfmPrintJS from '@diplodoc/transform/dist/js/print.js';
// @ts-ignore
import yfmJS from '@diplodoc/transform/dist/js/yfm.js';

export function generatePdfStaticMarkup(html: string) {
return `
<!doctype html>
<html>
Expand Down

0 comments on commit c941916

Please sign in to comment.