mirror of
https://github.com/jprichardson/node-fs-extra.git
synced 2026-01-18 16:13:55 +00:00
* Remove process.cwd() trick from test files * BREAKING: Switch from main to exports * Add fs-extra/esm ESM named import module, with just fs-extra methods Fixes #746
52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
'use strict'
|
|
|
|
const fs = require('fs')
|
|
const os = require('os')
|
|
const fse = require('../..')
|
|
const path = require('path')
|
|
const assert = require('assert')
|
|
|
|
/* global afterEach, beforeEach, describe, it */
|
|
|
|
describe('jsonfile-integration', () => {
|
|
let TEST_DIR
|
|
|
|
beforeEach(done => {
|
|
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'json')
|
|
fse.emptyDir(TEST_DIR, done)
|
|
})
|
|
|
|
afterEach(done => fse.remove(TEST_DIR, done))
|
|
|
|
describe('+ writeJsonSync / spaces', () => {
|
|
it('should read a file and parse the json', () => {
|
|
const obj1 = {
|
|
firstName: 'JP',
|
|
lastName: 'Richardson'
|
|
}
|
|
|
|
const file = path.join(TEST_DIR, 'file.json')
|
|
fse.writeJsonSync(file, obj1)
|
|
const data = fs.readFileSync(file, 'utf8')
|
|
assert.strictEqual(data, JSON.stringify(obj1) + '\n')
|
|
})
|
|
})
|
|
|
|
describe('+ writeJsonSync / EOL', () => {
|
|
it('should read a file and parse the json', () => {
|
|
const obj1 = {
|
|
firstName: 'JP',
|
|
lastName: 'Richardson'
|
|
}
|
|
|
|
const file = path.join(TEST_DIR, 'file.json')
|
|
fse.writeJsonSync(file, obj1, { spaces: 2, EOL: '\r\n' })
|
|
const data = fs.readFileSync(file, 'utf8')
|
|
assert.strictEqual(
|
|
data,
|
|
JSON.stringify(obj1, null, 2).replace(/\n/g, '\r\n') + '\r\n'
|
|
)
|
|
})
|
|
})
|
|
})
|