-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.test.ts
74 lines (58 loc) · 2.68 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
66
67
68
69
70
71
72
73
74
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 svg', () => {
beforeEach(() => {
sinon.stub(fs, 'mkdirSync').returnsArg(0);
});
afterEach(() => {
sinon.restore();
});
it('should export all components into svg files', 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.calledTwice;
expect(writeFileSync.firstCall).to.be.calledWithMatch('output/page1/Figma-Logo.svg');
expect(writeFileSync.secondCall).to.be.calledWithMatch('output/page1/Search.svg');
});
it('should create folder if component names contain slashes', async () => {
const writeFileSync = sinon.stub(fs, 'writeFileSync');
const fakePages = figmaDocument.createPage([figmaDocument.componentWithSlashedName]);
const pages = figma.getPages(fakePages);
await outputter({
output: 'output',
})(pages);
expect(writeFileSync).to.be.calledOnce;
expect(writeFileSync.firstCall).to.be.calledWithMatch('output/fakePage/icon/Figma-logo.svg');
});
describe('options', () => {
const fakePages = figmaDocument.createPage([figmaDocument.componentWithSlashedName]);
const pages = figma.getPages(fakePages);
it('should be able to customize "basename"', async () => {
const writeFileSync = sinon.stub(fs, 'writeFileSync');
await outputter({
output: 'output',
getBasename: (options) => `${options.pageName}-${options.basename}.svg`,
})(pages);
expect(writeFileSync).to.be.calledOnce;
expect(writeFileSync.firstCall).to.be.calledWithMatch('output/fakePage/icon/fakePage-Figma-logo.svg');
});
it('should be able to customize "dirname"', async () => {
const writeFileSync = sinon.stub(fs, 'writeFileSync');
await outputter({
output: 'output',
getBasename: (options) => `${options.pageName}-${options.basename}.svg`,
getDirname: (options) => `${options.dirname}`,
})(pages);
expect(writeFileSync).to.be.calledOnce;
expect(writeFileSync.firstCall).to.be.calledWithMatch('output/icon/fakePage-Figma-logo.svg');
});
});
});