-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.test.ts
65 lines (52 loc) · 1.99 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sinon from 'sinon';
import { expect } from 'chai';
import * as figmaDocument from '../../core/src/lib/_config.test';
import * as figma from '../../core/src/lib/figma';
import fs from 'fs';
import outputter from './index';
describe('outputter as svgstore', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let mkdirSync: sinon.SinonStub<any[], any>;
beforeEach(() => {
mkdirSync = sinon.stub(fs, 'mkdirSync').returnsArg(0);
});
afterEach(() => {
sinon.restore();
});
it('should create an svg with the page name as filename', async () => {
const writeFileSync = sinon.stub(fs, 'writeFileSync');
const document = figmaDocument.createDocument({ children: [figmaDocument.page1] });
const pages = figma.getPages(document);
await outputter({
output: 'output',
})(pages);
expect(writeFileSync).to.be.calledOnce;
expect(writeFileSync).to.be.calledWithMatch(
'output/page1.svg',
'id="page1/Figma-Logo"',
);
expect(mkdirSync).to.be.calledOnce;
expect(mkdirSync).to.be.calledWithMatch(
'output',
{ recursive: true },
);
});
it('should create folders and subfolders when pageName contains slashes', async () => {
const writeFileSync = sinon.stub(fs, 'writeFileSync');
const document = figmaDocument.createDocument({ children: [figmaDocument.page1WithSlashes] });
const pages = figma.getPages(document);
await outputter({
output: 'output',
})(pages);
expect(writeFileSync).to.be.calledOnce;
expect(writeFileSync).to.be.calledWithMatch(
'output/page1/subpath/subsubpath.svg',
'id="page1/subpath/subsubpath/Figma-Logo"',
);
expect(mkdirSync).to.be.calledOnce;
expect(mkdirSync).to.be.calledWithMatch(
'output/page1/subpath',
{ recursive: true },
);
});
});