uci-utils-read-lines/test/read-lines.test.js

57 lines
1.7 KiB
JavaScript

// let ignoreFiles = ['.npmignore','.gitignore']
import { readLines, writeLines } from '../src/read-lines.js'
import chai from 'chai'
import assertArrays from 'chai-arrays'
import { it } from 'mocha'
import { dirname } from 'dirname-filename-esm';
const __dirname = dirname(import.meta);
chai.use(assertArrays)
const expect = chai.expect
describe (
'Read a File of Lines to Array and vice versa',
function () {
readList()
writeList()
})
//****************** TESTS **********************
function readList() {
it('==> can read one or more files (no order) each line as element in an array with common directory', async function () {
const shouldbe = [ 'tests/',
'test/',
'*.test.js',
'testing/',
'example/',
'/node_modules/',
'/coverage/' ]
let result = await readLines(['.gitignore','.npmignore'],__dirname)
expect(result, 'list build failed').to.be.containingAllOf(shouldbe)
})
it('==> can read two files one relative the other absolute', async function () {
const shouldbe = [ 'tests/',
'test/',
'*.test.js',
'testing/',
'example/',
'/node_modules/',
'/coverage/' ]
let result = await readLines(['./test/.gitignore',__dirname+'/.npmignore'])
expect(result, 'list build failed').to.be.containingAllOf(shouldbe)
})
}
function writeList() {
it('==> can write an array items as lines in a file', async function () {
const shouldbe = await readLines(['.gitignore','.npmignore'],__dirname)
await writeLines(__dirname+'/combined.list',shouldbe)
const result = await readLines(['combined.list'],__dirname)
expect(result, 'list build failed').to.be.containingAllOf(shouldbe)
})
}