Adding test case for char encoding and being explicit about utf8 export.
This commit is contained in:
parent
31fbc937b0
commit
a656c6e678
|
@ -347,7 +347,7 @@ describe("/views", () => {
|
||||||
|
|
||||||
const setupExport = async () => {
|
const setupExport = async () => {
|
||||||
const table = await config.createTable()
|
const table = await config.createTable()
|
||||||
await config.createRow({ name: "test-name", description: "test-desc" })
|
await config.createRow({ name: "test-name", description: "ùúûü" })
|
||||||
return table
|
return table
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,11 +362,11 @@ describe("/views", () => {
|
||||||
const rows = JSON.parse(res.text)
|
const rows = JSON.parse(res.text)
|
||||||
expect(rows.length).toBe(1)
|
expect(rows.length).toBe(1)
|
||||||
expect(rows[0].name).toBe("test-name")
|
expect(rows[0].name).toBe("test-name")
|
||||||
expect(rows[0].description).toBe("test-desc")
|
expect(rows[0].description).toBe("ùúûü")
|
||||||
}
|
}
|
||||||
|
|
||||||
const assertCSVExport = (res) => {
|
const assertCSVExport = (res) => {
|
||||||
expect(res.text).toBe("\"name\",\"description\"\n\"test-name\",\"test-desc\"")
|
expect(res.text).toBe(`"name","description"\n"test-name","ùúûü"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should be able to export a table as JSON", async () => {
|
it("should be able to export a table as JSON", async () => {
|
||||||
|
|
|
@ -80,14 +80,16 @@ export function loadHandlebarsFile(path: string) {
|
||||||
* When return a file from the API need to write the file to the system temporarily so we
|
* When return a file from the API need to write the file to the system temporarily so we
|
||||||
* can create a read stream to send.
|
* can create a read stream to send.
|
||||||
* @param {string} contents the contents of the file which is to be returned from the API.
|
* @param {string} contents the contents of the file which is to be returned from the API.
|
||||||
|
* @param {string} encoding the encoding of the file to return (utf8 default)
|
||||||
* @return {Object} the read stream which can be put into the koa context body.
|
* @return {Object} the read stream which can be put into the koa context body.
|
||||||
*/
|
*/
|
||||||
export function apiFileReturn(contents: string) {
|
export function apiFileReturn(
|
||||||
|
contents: string,
|
||||||
|
encoding: BufferEncoding = "utf8"
|
||||||
|
) {
|
||||||
const path = join(budibaseTempDir(), uuid())
|
const path = join(budibaseTempDir(), uuid())
|
||||||
fs.writeFileSync(path, "\ufeff" + contents)
|
fs.writeFileSync(path, contents, { encoding })
|
||||||
const readerStream = fs.createReadStream(path)
|
return fs.createReadStream(path, { encoding })
|
||||||
readerStream.setEncoding("binary")
|
|
||||||
return readerStream
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function streamFile(path: string) {
|
export function streamFile(path: string) {
|
||||||
|
|
Loading…
Reference in New Issue