-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
41 lines (35 loc) · 1.48 KB
/
test.js
File metadata and controls
41 lines (35 loc) · 1.48 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
import test from 'ava';
import isSafeFilename, {assertSafeFilename, unsafeFilenameFixtures} from './index.js';
test('isSafeFilename - safe filenames', t => {
t.true(isSafeFilename('foo'));
t.true(isSafeFilename('foo.json'));
t.true(isSafeFilename('.gitignore'));
t.true(isSafeFilename('foo-bar_baz'));
t.true(isSafeFilename('...'));
});
test('isSafeFilename - unsafe filenames', t => {
for (const filename of unsafeFilenameFixtures) {
t.false(isSafeFilename(filename));
}
});
test('isSafeFilename - non-string input', t => {
t.false(isSafeFilename(123));
t.false(isSafeFilename(null));
t.false(isSafeFilename(undefined));
t.false(isSafeFilename({}));
});
test('assertSafeFilename - does not throw for safe filenames', t => {
t.notThrows(() => assertSafeFilename('foo'));
t.notThrows(() => assertSafeFilename('foo.json'));
});
test('assertSafeFilename - throws for unsafe filenames', t => {
for (const filename of unsafeFilenameFixtures) {
t.throws(() => assertSafeFilename(filename), {message: /^Unsafe filename:/});
}
});
test('assertSafeFilename - throws TypeError for non-string input', t => {
t.throws(() => assertSafeFilename(123), {instanceOf: TypeError, message: 'Expected a string'});
t.throws(() => assertSafeFilename(null), {instanceOf: TypeError, message: 'Expected a string'});
t.throws(() => assertSafeFilename(undefined), {instanceOf: TypeError, message: 'Expected a string'});
t.throws(() => assertSafeFilename({}), {instanceOf: TypeError, message: 'Expected a string'});
});