Skip to content

Commit

Permalink
fix formatting option (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem authored Jun 30, 2024
1 parent 731299e commit 183cc22
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function buildApp(src: string, dest: string, network: string = "mai
const content = (await readFile(file)).toString();
const new_file = await transpileJS(content, params, {
compileTypeScript: file.endsWith(".ts") || file.endsWith(".tsx"),
format: true,
format: config.format,
});
const new_logs: Log[] = new_file.logs.map((v) => {
return {
Expand Down Expand Up @@ -118,7 +118,7 @@ export async function buildApp(src: string, dest: string, network: string = "mai
const content = (await readFile(file)).toString();
const new_file = await transpileJS(content, params, {
compileTypeScript: file.endsWith(".ts") || file.endsWith(".tsx"),
format: true,
format: config.format,
});
const new_logs: Log[] = new_file.logs.map((v) => {
return {
Expand Down
50 changes: 50 additions & 0 deletions tests/unit/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,44 @@ const app_example_3_output = {
"/build/src/widget/alias.jsx": "return <h1>Hello world!</h1>;\n",
};

const unformated_example = {
"./bos.config.json": JSON.stringify({
...DEFAULT_CONFIG,
account: "test.near",
format: false
}),
"./widget/alias.tsx": "function add(a,b){return a+b} let result=add(1,2);console.log(result);",
};

const unformated_output = {
"/build/data.json": JSON.stringify({
"test.near": {}
}, null, 2) + "\n",
"/build/src/widget/alias.jsx": "function add(a,b){return a+b} let result=add(1,2);console.log(result);",
};

const formated_example = {
"./bos.config.json": JSON.stringify({
...DEFAULT_CONFIG,
account: "test.near",
format: true
}),
"./widget/alias.tsx": "function add(a,b){return a+b} let result=add(1,2);console.log(result);",
};

const formated_output = {
"/build/data.json": JSON.stringify({
"test.near": {}
}, null, 2) + "\n",
"/build/src/widget/alias.jsx": `function add(a, b) {
return a + b;
}
let result = add(1, 2);
console.log(result);
`,
};


const unmockedFetch = global.fetch;
const unmockedLog = global.log;

Expand Down Expand Up @@ -228,4 +266,16 @@ describe('build', () => {
await buildApp('/app_example_3', '/build');
expect(vol.toJSON('/build')).toEqual(app_example_3_output);
})

it('should format when format enabled', async () => {
vol.fromJSON(formated_example, '/formated_example');
await buildApp('/formated_example', '/build');
expect(vol.toJSON('/build')).toEqual(formated_output);
})

it('should not format when format disabled', async () => {
vol.fromJSON(unformated_example, '/unformated_example');
await buildApp('/unformated_example', '/build');
expect(vol.toJSON('/build')).toEqual(unformated_output);
})
})

0 comments on commit 183cc22

Please sign in to comment.