Skip to content

Commit 183cc22

Browse files
authored
fix formatting option (#120)
1 parent 731299e commit 183cc22

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

lib/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export async function buildApp(src: string, dest: string, network: string = "mai
8181
const content = (await readFile(file)).toString();
8282
const new_file = await transpileJS(content, params, {
8383
compileTypeScript: file.endsWith(".ts") || file.endsWith(".tsx"),
84-
format: true,
84+
format: config.format,
8585
});
8686
const new_logs: Log[] = new_file.logs.map((v) => {
8787
return {
@@ -118,7 +118,7 @@ export async function buildApp(src: string, dest: string, network: string = "mai
118118
const content = (await readFile(file)).toString();
119119
const new_file = await transpileJS(content, params, {
120120
compileTypeScript: file.endsWith(".ts") || file.endsWith(".tsx"),
121-
format: true,
121+
format: config.format,
122122
});
123123
const new_logs: Log[] = new_file.logs.map((v) => {
124124
return {

tests/unit/build.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,44 @@ const app_example_3_output = {
188188
"/build/src/widget/alias.jsx": "return <h1>Hello world!</h1>;\n",
189189
};
190190

191+
const unformated_example = {
192+
"./bos.config.json": JSON.stringify({
193+
...DEFAULT_CONFIG,
194+
account: "test.near",
195+
format: false
196+
}),
197+
"./widget/alias.tsx": "function add(a,b){return a+b} let result=add(1,2);console.log(result);",
198+
};
199+
200+
const unformated_output = {
201+
"/build/data.json": JSON.stringify({
202+
"test.near": {}
203+
}, null, 2) + "\n",
204+
"/build/src/widget/alias.jsx": "function add(a,b){return a+b} let result=add(1,2);console.log(result);",
205+
};
206+
207+
const formated_example = {
208+
"./bos.config.json": JSON.stringify({
209+
...DEFAULT_CONFIG,
210+
account: "test.near",
211+
format: true
212+
}),
213+
"./widget/alias.tsx": "function add(a,b){return a+b} let result=add(1,2);console.log(result);",
214+
};
215+
216+
const formated_output = {
217+
"/build/data.json": JSON.stringify({
218+
"test.near": {}
219+
}, null, 2) + "\n",
220+
"/build/src/widget/alias.jsx": `function add(a, b) {
221+
return a + b;
222+
}
223+
let result = add(1, 2);
224+
console.log(result);
225+
`,
226+
};
227+
228+
191229
const unmockedFetch = global.fetch;
192230
const unmockedLog = global.log;
193231

@@ -228,4 +266,16 @@ describe('build', () => {
228266
await buildApp('/app_example_3', '/build');
229267
expect(vol.toJSON('/build')).toEqual(app_example_3_output);
230268
})
269+
270+
it('should format when format enabled', async () => {
271+
vol.fromJSON(formated_example, '/formated_example');
272+
await buildApp('/formated_example', '/build');
273+
expect(vol.toJSON('/build')).toEqual(formated_output);
274+
})
275+
276+
it('should not format when format disabled', async () => {
277+
vol.fromJSON(unformated_example, '/unformated_example');
278+
await buildApp('/unformated_example', '/build');
279+
expect(vol.toJSON('/build')).toEqual(unformated_output);
280+
})
231281
})

0 commit comments

Comments
 (0)