forked from jscad/OpenJSCAD.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.test.js.hold
283 lines (240 loc) · 10.5 KB
/
cli.test.js.hold
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
// FIXME: tests are basic 'is the output file there, how big is it' for now, actual checks are needed !!
const test = require('ava')
const path = require('path')
const { execSync } = require('child_process')
const fs = require('fs')
const examplesPath = path.resolve('./node_modules/@jscad/examples')
const coreExamplesPath = path.join(examplesPath, 'core')
const parametersExamplesPath = path.join(examplesPath, 'parameters')
const variousExamplesPath = path.join(examplesPath, 'various')
const scadExamplesPath = path.join(examplesPath, 'formats', 'scad')
const amfExamplesPath = path.join(examplesPath, 'formats', 'amf')
const stlExamplesPath = path.join(examplesPath, 'formats', 'stl')
function almostEquals (t, observed, expected, precision) {
t.is(Math.abs(expected - observed) < precision, true)
}
// NOTE : use // --inspect --debug-brk to debug node commands in chrome
test.afterEach.always(t => {
// this runs after each test and other test hooks, even if they failed
// remove created file
try {
fs.unlinkSync(t.context.outputPath)
} catch (err) {}
})
test.beforeEach(t => {
let jscadPath = './cli'
t.context = {
jscadPath: path.resolve(__dirname, jscadPath)
}
})
// console.log('stl', fs.statSync(outputPath).size)
// core functionality
test('jscad (basic, input file only)', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(variousExamplesPath, '/logo.jscad')
const expPath = path.join(variousExamplesPath, '/logo.stl')
t.context = { outputPath: expPath }
const cmd = `node ${jscadPath} ${inputPath} -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
// console.log('fs.statSync(expPath).size', fs.statSync(expPath).size)
almostEquals(t, fs.statSync(expPath).size, 338371, 3) // this has to be set this large because of the cross platform differences
})
test('require() support: loading a design from a folder', t => {
const jscadPath = t.context.jscadPath
const designPath = path.join(coreExamplesPath, '/module-design')
const outputPath = 'test.stl'
const expPath = outputPath
t.context = { outputPath }
// first install the module's dependencies, just in case
execSync('npm install', { cwd: designPath })
// note that in this case, we pass a FOLDER to the CLI, not a file
const cmd = `node ${jscadPath} ${designPath} --length 12.4 -o ${outputPath} -of stla -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
almostEquals(t, fs.statSync(outputPath).size, 1119, 2)
})
test('jscad with parameters', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(parametersExamplesPath, '/name-plate.jscad')
const outputPath = 'JustMe_Geek_name_plate.stl'
const expPath = outputPath
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} --name "Just Me" --title "Geek" -o ${outputPath} -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
almostEquals(t, fs.statSync(expPath).size, 133184, 50)
})
test('jscad with complex/ multiple type of parameters', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(parametersExamplesPath, '/grille.jscad')
const outputPath = 'grille.stl'
const expPath = outputPath
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} --outerwidth 176.25 --outerdepth 15.2 --numdividers 4 --addlooseners "Yes" --show "grille" --mouseears 0 --quality 0 -o ${outputPath} -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
almostEquals(t, fs.statSync(expPath).size, 216484, 50)
})
// NOTE : echo() will likely be deprecated soon, but keeping this around for now
/* test('echo() support', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(coreExamplesPath, '/echo.jscad')
const outputPath = 'test.jscad'
const expPath = outputPath
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${outputPath} -of jscad -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
almostEquals(t, fs.statSync(outputPath).size, 683, 2)
}) */
// IO testing
test('jscad to stl (ascii)', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(variousExamplesPath, '/logo.jscad')
const outputPath = 'test.stl'
const expPath = 'test.stl'
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${outputPath} -of stla -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
almostEquals(t, fs.statSync(expPath).size, 338371, 4)
})
test('jscad to stl(binary)', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(variousExamplesPath, '/logo.jscad')
const outputPath = 'test.stl'
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${outputPath} -of stlb -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(outputPath))
almostEquals(t, fs.statSync(outputPath).size, 74284, 2)
})
test('jscad to dxf', t => {
const inputPath = path.join(coreExamplesPath, '/cnc-cutout.jscad')
const outputPath = 'test.dxf'
const jscadPath = t.context.jscadPath
const expPath = outputPath
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${outputPath} -of dxf`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
almostEquals(t, fs.statSync(outputPath).size, 18991, 2)
})
// FIXME: svg not working
test('jscad to svg', t => {
const inputPath = path.join(coreExamplesPath, '/chain_hull.jscad')
const outputPath = 'test.svg'
const jscadPath = t.context.jscadPath
const expPath = outputPath
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${outputPath} -of svg`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
almostEquals(t, fs.statSync(outputPath).size, 8291, 2)
})
/* FIXME: AMF files DOUBLED in size since last time
test('jscad to amf', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(examplesPath, '/logo.jscad')
const outputPath = 'test.amf'
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${outputPath} -of amf -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(outputPath))
almostEquals(t, fs.statSync(outputPath).size, 397341, 50)
})
test('jscad to amf(with transparency)', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(coreExamplesPath, '/transparency.jscad')
const outputPath = 'test.amf'
const expPath = outputPath
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${outputPath} -of amf -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
almostEquals(t, fs.statSync(outputPath).size, 240108, 50)
}) */
/* FIXME : openscad support broken in V2 for now
test('openscad to stl (ascii)', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(scadExamplesPath, '/example001.scad')
const outputPath = 'test.stl'
const expPath = 'test.stl'
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${outputPath} -of stla -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
console.log('fs.statSync(outputPath).size', fs.statSync(outputPath).size)
almostEquals(t, fs.statSync(outputPath).size, 629242, 100)
})
test('openscad to stl(binary)', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(examplesPath, '/example001.scad')
const outputPath = 'test.stl'
// const expPath = path.join(examplesPath, '/logo-binary.stl')
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${outputPath} -of stlb -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(outputPath))
// t.deepEqual(fs.readFileSync(expPath), fs.readFileSync(outputPath))
almostEquals(t, fs.statSync(outputPath).size, 111684, 2)
})
test('openscad to amf', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(examplesPath, '/example001.scad')
const outputPath = 'test.amf'
const expPath = outputPath
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${outputPath} -of amf -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
almostEquals(t, fs.statSync(outputPath).size, 626177, 120)
})
test('openscad to jscad', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(examplesPath, '/example001.scad')
const outputPath = 'test.jscad'
const expPath = outputPath
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${outputPath} -of jscad -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
almostEquals(t, fs.statSync(outputPath).size, 646, 2)
})
test('openscad to jscad to stl', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(examplesPath, '/example001.scad')
const jscadOutputPath = 'test.jscad'
const outputPath = 'test.stl'
const expPath = outputPath
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${jscadOutputPath} -of jscad -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
const cmd2 = `node ${jscadPath} ${jscadOutputPath} -o ${outputPath}`
execSync(cmd2, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
almostEquals(t, fs.statSync(outputPath).size, 111684, 2)
}) */
test('stl to jscad', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(stlExamplesPath, '/thing_7-Zomboe.stl')
const outputPath = 'test.jscad'
const expPath = outputPath
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${outputPath} -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
almostEquals(t, fs.statSync(outputPath).size, 3780879, 2)
})
test('amf to jscad', t => {
const jscadPath = t.context.jscadPath
const inputPath = path.join(amfExamplesPath, '/Amf_Cube.amf')
const outputPath = 'test.jscad'
const expPath = outputPath
t.context = { outputPath }
const cmd = `node ${jscadPath} ${inputPath} -o ${outputPath} -add-metadata false`
execSync(cmd, { stdio: [0, 1, 2] })
t.deepEqual(true, fs.existsSync(expPath))
almostEquals(t, fs.statSync(outputPath).size, 1754, 2)
})