-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.js
47 lines (40 loc) · 1.05 KB
/
test.js
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
const test = require("ava");
const path = require("path");
const fs = require("fs-extra");
const casex = require("casex");
const replace = require("replace-in-file");
const fixturez = require('fixturez');
const writeFilesAtomic = require('write-files-atomic');
let conf = require("./lib/conf.json");
const f = fixturez(__dirname);
test('writes files', async t => {
let tempDir = f.temp();
let name = path.join(tempDir, 'name.txt');
let namespace = path.join(tempDir, 'namespace.txt');
await writeFilesAtomic([
{ filePath: name, fileContents: 'Mynamer' },
{ filePath: namespace, fileContents: 'namespace Myname' },
]);
let options = {
files: [
name,
namespace
],
from: [
new RegExp('Mynamer', "g"),
new RegExp('namespace Myname', "g")
],
to: [
'Mytheme',
'namespace MyTheme'
]
};
try {
const changes = await replace(options)
t.is(await fs.readFile(namespace, 'utf8'), 'namespace MyTheme');
t.is(await fs.readFile(name, 'utf8'), 'Mytheme');
}
catch (error) {
console.error('Error occurred:', error);
}
});