UNPKG

2.48 kBJavaScriptView Raw
1const assert = require('assert')
2const { deepEqual } = require('assert-diff')
3const clone = require('../../src/clone')
4const WroteContext = require('../context/WroteContext')
5
6const { equal } = assert
7
8const cloneTestSuite = {
9 context: WroteContext,
10 async 'should clone a directory'({
11 FIXTURES_TEST_DIR, TEMP_TEST_DIR, readFixturesStructure,
12 readTempStructure, readTemp, readFixtures,
13 }) {
14 await clone({
15 to: TEMP_TEST_DIR,
16 from: FIXTURES_TEST_DIR,
17 })
18
19 const expected = await readFixturesStructure()
20 const actual = await readTempStructure()
21 deepEqual(actual, expected)
22
23 const expectedRead = await readFixtures()
24 const actualRead = await readTemp()
25 deepEqual(actualRead, expectedRead)
26 },
27 async 'should use regular expressions'({
28 FIXTURES_TEST_DIR, TEMP_TEST_DIR, readFixtures,
29 readTemp,
30 }) {
31 await clone({
32 to: TEMP_TEST_DIR,
33 from: FIXTURES_TEST_DIR,
34 regexes: [
35 {
36 re: /sys\.stderr\.write('test-file')/,
37 // eslint-disable-next-line quotes
38 replacement: "sys.stdout.write('updated-test-file')",
39 },
40 {
41 re: /file/g,
42 replacement: 'UFO',
43 },
44 ],
45 })
46
47 const expected = await readFixtures()
48 expected.subdirectory['file.data'] = 'this is a UFO with some data\n'
49 expected.subdirectory['file2.data'] = 'this is another UFO with some other data\n'
50 expected.subdirectory2['file3.data'] = 'a UFO in another subdirectory\n'
51 expected.subdirectory2.subsubdir['file4.py'] = 'sys.stderr.write(\'test-UFO\')\n'
52
53 const actual = await readTemp()
54 deepEqual(actual, expected)
55 },
56 async 'should throw'() {
57 try {
58 Error.stackTraceLimit = Infinity
59 await clone({
60 regexes: [
61 {
62 re: /test/,
63 replacement: 'test',
64 },
65 ],
66 to: 'local-dir',
67 from: 'local-path-does-not-exist',
68 })
69 throw new Error('should have thrown')
70 } catch ({ stack, code }) {
71 equal(code, 'ENOENT')
72 assert(/should throw/.test(stack))
73 }
74 },
75}
76
77module.exports = cloneTestSuite