Skip to content

Commit feebd26

Browse files
committed
test(cli): reworked test suites to use new options
1 parent 9549866 commit feebd26

File tree

3 files changed

+86
-20
lines changed

3 files changed

+86
-20
lines changed

packages/cli/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ npm install -g @jscad/cli
4040
```
4141
Once installed, the CLI can be invoked using
4242
```
43-
jscad -v
44-
jscad
43+
jscad --help
4544
```
4645

4746
### Install the CLI as Part of a Project
@@ -54,10 +53,9 @@ npm install -D @jscad/cli
5453

5554
This will add the CLI package as a development dependency. The CLI can be invoked using
5655
```
57-
npx jscad -v
58-
npx jscad
56+
npx jscad --help
5957
```
60-
These two commands will show the version of the CLI, and a general help message.
58+
These two commands will show the various options of the CLI, and a general usage example.
6159

6260
### Using the CLI
6361

@@ -71,24 +69,26 @@ Examples:
7169

7270
```jscad frog.stl -o test.js # -- convert frog.stl to test.js```
7371

74-
```jscad mydesign.js -of amf # -- convert mydesign.js into mydesign.amf```
72+
```jscad mydesign.js -f amf # -- convert mydesign.js into mydesign.amf```
7573

7674
For multi-part models, you can pass the `generateParts` flag `-gp` to output each part as a separate, numbered file:
7775

78-
```jscad mydesign.js -gp # -- convert mydesign.js into mydesign-part-1-of-2.stl and mydesign-part-2-of-2.stl```
76+
```jscad mydesign.js -p # -- convert mydesign.js into mydesign-part-1-of-2.stl and mydesign-part-2-of-2.stl```
7977

8078
You may also pass the `zip` flag `-z` to zip generated files into one .zip file:
8179

8280
```jscad mydesign.js -z # -- convert mydesign.js into mydesign.zip which contains: mydesign.stl```
8381

84-
```jscad mydesign.js -gp -z # -- convert mydesign.js into mydesign.zip which contains: mydesign-part-1-of-2.stl and mydesign-part-2-of-2.stl```
82+
```jscad mydesign.js -p -z # -- convert mydesign.js into mydesign.zip which contains: mydesign-part-1-of-2.stl and mydesign-part-2-of-2.stl```
8583

8684
The '-o' option can be used to control where the output will be placed.
8785
While, the '-of' option can be used to control the format of the output.
8886

8987
You can also provide the parameters to a design by passing --<paramName> <value> to the CLI.
9088

91-
```jscad mydesign.js --name "Just Me" --title "Geek" -o output.stl```
89+
```jscad -o ouptput.stl mydesign.js -- --name "Just Me" --title "Geek"```
90+
91+
NOTE: Be sure to seperate the parameters with '--'
9292

9393
Also, design projects (directories) can be used as the input to the CLI.
9494

@@ -118,7 +118,7 @@ ln -s node_modules/@jscad/examples ./examples
118118
The examples are just single file designs, or multiple file projects.
119119
```
120120
npx jscad examples/core/booleans/basicBooleans.js -o ./test.stl
121-
npx jscad examples/module-design/ -of dxf
121+
npx jscad examples/module-design/ -f dxf
122122
```
123123

124124
## Documentation

packages/cli/cli.conversions.test.js

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ test('cli (conversions STL)', (t) => {
9696

9797
t.context.file3Path = file3Path
9898

99-
cmd = `node ${cliPath} ${file2Path} -o ${file3Path} -v -add-metadata false`
99+
cmd = `node ${cliPath} ${file2Path} -o ${file3Path} -v --add-metadata`
100100
execSync(cmd, { stdio: [0, 1, 2] })
101101
t.true(fs.existsSync(file3Path))
102102
})
@@ -129,7 +129,7 @@ test('cli (conversions DXF)', (t) => {
129129

130130
t.context.file3Path = file3Path
131131

132-
cmd = `node ${cliPath} ${file2Path} -of js`
132+
cmd = `node ${cliPath} ${file2Path} -f js`
133133
execSync(cmd, { stdio: [0, 1, 2] })
134134
t.true(fs.existsSync(file3Path))
135135
})
@@ -162,7 +162,40 @@ test('cli (conversions JSON)', (t) => {
162162

163163
t.context.file3Path = file3Path
164164

165-
cmd = `node ${cliPath} ${file2Path} -of js`
165+
cmd = `node ${cliPath} ${file2Path} -f js`
166+
execSync(cmd, { stdio: [0, 1, 2] })
167+
t.true(fs.existsSync(file3Path))
168+
})
169+
170+
test('cli (conversions OBJ)', (t) => {
171+
const testID = 17
172+
173+
// convert from JSCAD to OBJ
174+
const file1Path = createJscad(testID)
175+
t.true(fs.existsSync(file1Path))
176+
177+
t.context.file1Path = file1Path
178+
179+
const file2Name = `./test${testID}.obj`
180+
const file2Path = path.resolve(cwd(), file2Name)
181+
t.false(fs.existsSync(file2Path))
182+
183+
t.context.file2Path = file2Path
184+
185+
const cliPath = t.context.cliPath
186+
187+
let cmd = `node ${cliPath} ${file1Path} -o ${file2Path}`
188+
execSync(cmd, { stdio: [0, 1, 2] })
189+
t.true(fs.existsSync(file2Path))
190+
191+
// convert from OBJ to JS
192+
const file3Name = `./test${testID}.js`
193+
const file3Path = path.resolve(cwd(), file3Name)
194+
t.false(fs.existsSync(file3Path))
195+
196+
t.context.file3Path = file3Path
197+
198+
cmd = `node ${cliPath} ${file2Path} -f js`
166199
execSync(cmd, { stdio: [0, 1, 2] })
167200
t.true(fs.existsSync(file3Path))
168201
})
@@ -195,7 +228,7 @@ test('cli (conversions SVG)', (t) => {
195228

196229
t.context.file3Path = file3Path
197230

198-
cmd = `node ${cliPath} ${file2Path} -of js`
231+
cmd = `node ${cliPath} ${file2Path} -f js`
199232
execSync(cmd, { stdio: [0, 1, 2] })
200233
t.true(fs.existsSync(file3Path))
201234
})
@@ -228,7 +261,40 @@ test('cli (conversions X3D)', (t) => {
228261

229262
t.context.file3Path = file3Path
230263

231-
cmd = `node ${cliPath} ${file2Path} -of js`
264+
cmd = `node ${cliPath} ${file2Path} -f js`
265+
execSync(cmd, { stdio: [0, 1, 2] })
266+
t.true(fs.existsSync(file3Path))
267+
})
268+
269+
test('cli (conversions 3MF)', (t) => {
270+
const testID = 16
271+
272+
// convert from JSCAD to 3MF
273+
const file1Path = createJscad(testID)
274+
t.true(fs.existsSync(file1Path))
275+
276+
t.context.file1Path = file1Path
277+
278+
const file2Name = `./test${testID}.3mf`
279+
const file2Path = path.resolve(cwd(), file2Name)
280+
t.false(fs.existsSync(file2Path))
281+
282+
t.context.file2Path = file2Path
283+
284+
const cliPath = t.context.cliPath
285+
286+
let cmd = `node ${cliPath} ${file1Path} -o ${file2Path}`
287+
execSync(cmd, { stdio: [0, 1, 2] })
288+
t.true(fs.existsSync(file2Path))
289+
290+
// convert from 3MF to JS
291+
const file3Name = `./test${testID}.js`
292+
const file3Path = path.resolve(cwd(), file3Name)
293+
t.false(fs.existsSync(file3Path))
294+
295+
t.context.file3Path = file3Path
296+
297+
cmd = `node ${cliPath} ${file2Path} -f js`
232298
execSync(cmd, { stdio: [0, 1, 2] })
233299
t.true(fs.existsSync(file3Path))
234300
})

packages/cli/cli.parameters.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ test('cli (single input file, output format)', (t) => {
111111

112112
const cliPath = t.context.cliPath
113113

114-
const cmd = `node ${cliPath} ${inputPath} -of dxf`
114+
const cmd = `node ${cliPath} ${inputPath} -f dxf`
115115
execSync(cmd, { stdio: [0, 1, 2] })
116116
t.true(fs.existsSync(outputPath))
117117
})
@@ -167,7 +167,7 @@ test('cli (folder, output format)', (t) => {
167167

168168
const cliPath = t.context.cliPath
169169

170-
const cmd = `node ${cliPath} ${folderPath} -of dxf`
170+
const cmd = `node ${cliPath} ${folderPath} -f dxf`
171171
execSync(cmd, { stdio: [0, 1, 2] })
172172
t.true(fs.existsSync(outputPath))
173173
})
@@ -188,7 +188,7 @@ test('cli (single input file, parameters)', (t) => {
188188

189189
const cliPath = t.context.cliPath
190190

191-
const cmd = `node ${cliPath} ${inputPath} --segments 32 --nothing "Yes"`
191+
const cmd = `node ${cliPath} ${inputPath} -- --segments 32 --nothing "Yes"`
192192
execSync(cmd, { stdio: [0, 1, 2] })
193193
t.true(fs.existsSync(outputPath))
194194
})
@@ -241,7 +241,7 @@ test('cli (single input file, multiple output files)', (t) => {
241241

242242
const cliPath = t.context.cliPath
243243

244-
const cmd = `node ${cliPath} ${inputPath} -gp`
244+
const cmd = `node ${cliPath} -p ${inputPath}`
245245
execSync(cmd, { stdio: [0, 1, 2] })
246246
t.true(fs.existsSync(outputPath1))
247247
t.true(fs.existsSync(outputPath2))
@@ -265,7 +265,7 @@ test('cli (single multipart input file, zipped output file)', async (t) => {
265265

266266
const cliPath = t.context.cliPath
267267

268-
const cmd = `node ${cliPath} ${inputPath} -gp -z`
268+
const cmd = `node ${cliPath} ${inputPath} -p -z`
269269
execSync(cmd, { stdio: [0, 1, 2] })
270270
t.true(fs.existsSync(outputPath))
271271

0 commit comments

Comments
 (0)