-
Notifications
You must be signed in to change notification settings - Fork 999
Expand file tree
/
Copy pathfile-system.spec.ts
More file actions
83 lines (61 loc) · 2.62 KB
/
file-system.spec.ts
File metadata and controls
83 lines (61 loc) · 2.62 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { Config, FileSystem, noop } from '@browserless.io/browserless';
import { readFile, unlink } from 'fs/promises';
import { expect } from 'chai';
const filePath = '/tmp/_browserless_test_fs_';
describe('File-System', () => {
afterEach(async () => unlink(filePath).catch(noop));
it('saves and encodes files', async () => {
const mySecretContents = 'pony-foo';
const config = new Config();
config.setToken('browserless.io');
const f = new FileSystem(config);
await f.append(filePath, mySecretContents, true);
expect(await f.read(filePath, true)).to.eql([mySecretContents]);
const rawText = (await readFile(filePath)).toString();
expect(rawText.toString()).to.not.include(mySecretContents);
});
it('saves files without encoding', async () => {
const mySecretContents = 'pony-foo';
const config = new Config();
config.setToken('browserless.io');
const f = new FileSystem(config);
await f.append(filePath, mySecretContents, false);
expect(await f.read(filePath, false)).to.eql([mySecretContents]);
const rawText = (await readFile(filePath)).toString();
expect(rawText.toString()).to.include(mySecretContents);
});
it('appends newlines to files and encodes them', async () => {
const mySecretContents = 'pony-foo';
const moreSecretContents = 'pony-pony-foo-foo';
const config = new Config();
config.setToken('browserless.io');
const f = new FileSystem(config);
await f.append(filePath, mySecretContents, true);
expect(await f.read(filePath, true)).to.eql([mySecretContents]);
await f.append(filePath, moreSecretContents, true);
expect(await f.read(filePath, true)).to.eql([
mySecretContents,
moreSecretContents,
]);
const rawText = (await readFile(filePath)).toString();
expect(rawText).to.not.include(mySecretContents);
expect(rawText).to.not.include(moreSecretContents);
});
it('appends newlines to files and does not encode them', async () => {
const mySecretContents = 'pony-foo';
const moreSecretContents = 'pony-pony-foo-foo';
const config = new Config();
config.setToken('browserless.io');
const f = new FileSystem(config);
await f.append(filePath, mySecretContents, false);
expect(await f.read(filePath, false)).to.eql([mySecretContents]);
await f.append(filePath, moreSecretContents, false);
expect(await f.read(filePath, false)).to.eql([
mySecretContents,
moreSecretContents,
]);
const rawText = (await readFile(filePath)).toString();
expect(rawText).to.include(mySecretContents);
expect(rawText).to.include(moreSecretContents);
});
});