Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x | import * as yaml from 'yaml';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as mock from 'mock-fs';
import {YAML} from './yaml';
import {deepStrictEqual, strictEqual} from 'assert';
const cwd = process.cwd();
const here = (filename: string) => path.join(cwd, filename);
const content = `
# example
name: thomas
`;
describe('YAML', () => {
beforeEach(() =>
mock({
[here('hello.yml')]: content,
})
);
afterEach(() => mock.restore());
it('should get parsedContent', async () => {
const jsonFile = new YAML({basename: 'hello.yml'});
deepStrictEqual(await jsonFile.parsedContent, {name: 'thomas'});
});
it('should set property and retain comment', async () => {
const jsonFile = new YAML({basename: 'hello.yml'});
await jsonFile.set('love', true);
const result = {name: 'thomas', love: true};
const commentResult = `# example\n${yaml.stringify(result)}`;
strictEqual(fs.readFileSync(here('hello.yml'), 'utf8'), commentResult);
deepStrictEqual(await jsonFile.parsedContent, result);
});
});
|