-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
149 lines (148 loc) · 5.61 KB
/
Copy pathtest.js
File metadata and controls
149 lines (148 loc) · 5.61 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
let nosf = require(__dirname + "/../src/nosf.js");;
const { expect, assert } = require("chai");
describe("Test for NOSF", function() {
it("can load everything", async function() {
await nosf.load();
});
it("can use executeSync function", function() {
const output = nosf.executeSync("echo 'This is a request'");
expect(output).to.equal("This is a request\n");
});
it("can use executeAsync function", async function() {
const output = await nosf.executeAsync("echo 'This is a request'");
expect(output).to.equal("This is a request\n");
});
it("can use findFilesAsync function", async function() {
const output = await nosf.findFilesAsync(__dirname + "/files/file-{one,two,three}.txt");
expect(output.length).to.equal(3);
});
it("can use dumpToExcel function", async function() {
const file = __dirname + "/files/example-2.xlsx";
try {
nosf.fs.unlinkSync(file);
} catch (error) {}
const output = await nosf.dumpToExcel(file, [{
fruit: "orange",
color: "orange"
}, {
fruit: "banana",
color: "yellow"
}, {
fruit: "apple",
color: "red"
}]);
const exists = nosf.fs.existsSync(file);
expect(exists).to.equal(true);
});
it("can use «download» package", async function() {
const { download } = nosf;
await download("https://www.example.com", __dirname + "/files/example.html");
require("fs").existsSync(__dirname + "/files/example.html");
});
it("can use «fs-extra» package", async function() {
const { fs } = nosf;
const directory = __dirname + "/files/deep/inside/directory";
const existsBefore = fs.existsSync(directory);
expect(existsBefore).to.equal(false);
fs.ensureDirSync(directory);
const existsAfter = fs.existsSync(directory);
expect(existsAfter).to.equal(true);
fs.rmSync(__dirname + "/files/deep", { force: true, recursive: true });
});
it("can use «globby» package", async function() {
let { globby } = nosf;
const files = globby.globbySync(__dirname + "/files/file-{one,two,three}.txt");
expect(files.length).to.equal(3);
});
it("can use «which» package", function() {
let { which } = nosf;
const hasNode = which.sync("node", { nothrow: true });
expect(hasNode).to.not.equal(null);
const hasUnrealistic = which.sync("some-unrealistic-binary", { nothrow: true });
expect(hasUnrealistic).to.equal(null);
});
it("can use «chalk» package", async function() {
let { chalk } = nosf;
chalk = await new chalk.Chalk();
console.log(chalk.red.bold("Hello in red and bold color!"));
});
it("can use «adm-zip» package", function() {
this.timeout(10 * 1000);
let { admZip } = nosf;
const zip = new admZip();
zip.addFile("test.txt", Buffer.from("This is some text.", "utf8"));
zip.addLocalFile(__dirname + "/files/example.html");
zip.addLocalFile(__dirname + "/files/file-one.txt");
zip.addLocalFile(__dirname + "/files/file-two.txt");
zip.addLocalFile(__dirname + "/files/file-three.txt");
zip.addLocalFile(__dirname + "/files/file-four.txt");
zip.writeZip(__dirname + "/files/all.zip");
});
it("can use «xlsx» package", function() {
this.timeout(10 * 1000);
let { xlsx } = nosf;
const worksheet = xlsx.utils.json_to_sheet([{
name: "Homer Simpson",
age: 32
}, {
name: "Peter Griffin",
age: 36
}, {
name: "San Goku",
age: 27
}]);
const workbook = xlsx.utils.book_new();
xlsx.utils.book_append_sheet(workbook, worksheet, "Cartoon_characters");
xlsx.writeFile(workbook, __dirname + "/files/example.xlsx");
});
it("can use «readline-sync» package", function() {
this.timeout(10 * 1000);
let { readlineSync } = nosf;
const answer = readlineSync.question("Are you there yet, user?");
console.log(answer);
});
it("can use «inquirer» package", async function() {
this.timeout(30 * 1000);
let { inquirer } = nosf;
const answers = await inquirer.prompt([{
name: "name",
message: "What is your name?"
}, {
name: "age",
message: "How old are you?"
}, {
type: "list",
name: "gender",
message: "What is your gender, male or female?",
choices: ["male", "female"]
}, {
name: "origin",
message: "Where do you come from?"
}]);
console.log(answers);
});
it("can use «spinnies» package", async function() {
this.timeout(10 * 1000);
let { spinnies: Spinnies } = nosf;
const spinnies = new Spinnies();
spinnies.add('spinner-1', { text: 'I am a spinner' });
spinnies.add('spinner-2', { text: 'I am another spinner' });
setTimeout(() => {
spinnies.succeed('spinner-1', { text: 'Success!' });
spinnies.fail('spinner-2', { text: 'Fail :(' });
}, 2000);
});
it("can use «cli-table» package", async function() {
this.timeout(10 * 1000);
let { cliTable } = nosf;
const table = new cliTable({
head: ["Nombre", "Edad"]
});
table.push(
["Carl", 33],
["Codos", 40],
["Matusalen", 900]
);
console.log(table.toString());
});
});