Skip to content

Commit c0d3731

Browse files
committed
fix: clean up the app run test
1 parent 5c42be4 commit c0d3731

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

packages/build/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ exports.prettier = require('./bin/run-prettier');
1010
exports.tslint = require('./bin/run-tslint');
1111
exports.nyc = require('./bin/run-nyc');
1212
exports.dist = require('./bin/select-dist');
13+
exports.mocha = require('./bin/run-mocha');
14+
exports.clean = require('./bin/run-clean');
1315

1416
const utils = require('./bin/utils');
1517
exports.runCLI = utils.runCLI;

packages/cli/test/app-run.test.js

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,61 @@
88
const path = require('path');
99
const assert = require('yeoman-assert');
1010
const helpers = require('yeoman-test');
11-
1211
const lerna = require('lerna');
13-
function lernaBootstrap() {
14-
const cmd = new lerna.BootstrapCommand('', {
15-
loglevel: 'silent',
16-
});
17-
return cmd.run();
18-
}
19-
20-
const runShell = require('@loopback/build').runShell;
12+
const build = require('@loopback/build');
2113

2214
describe('app-generator', function() {
2315
const generator = path.join(__dirname, '../generators/app');
2416
const rootDir = path.join(__dirname, '../../..');
2517
const sandbox = path.join(__dirname, '../../_sandbox');
2618
const cwd = process.cwd();
19+
const appName = '@loopback/sandbox-app';
2720
const props = {
28-
name: 'myApp',
29-
description: 'My app for LoopBack 4',
21+
name: appName,
22+
description: 'My sandbox app for LoopBack 4',
3023
outdir: sandbox,
3124
};
3225

33-
// WARNING: It takes a while to run `lerna bootstrap`
34-
this.timeout(0);
35-
before(() => {
36-
return helpers
26+
before(async () => {
27+
await helpers
3728
.run(generator)
3829
.inDir(sandbox)
30+
// Mark it private to prevent accidental npm publication
31+
.withOptions({private: true})
3932
.withPrompts(props);
4033
});
4134

42-
it('passes `npm test` for the generated project', async () => {
35+
// Run `lerna bootstrap --scope @loopback/sandbox-app`
36+
// WARNING: It takes a while to run `lerna bootstrap`
37+
this.timeout(0);
38+
before(async () => {
4339
process.chdir(rootDir);
44-
await lernaBootstrap();
40+
await lernaBootstrap(appName);
41+
});
42+
43+
it('passes `npm test` for the generated project', () => {
4544
process.chdir(sandbox);
4645
return new Promise((resolve, reject) => {
47-
runShell('npm', ['test', '--', '--allow-console-logs']).on(
48-
'close',
49-
code => {
50-
process.chdir(cwd);
46+
build
47+
.runShell('npm', ['test', '--', '--allow-console-logs'])
48+
.on('close', code => {
5149
assert.equal(code, 0);
5250
resolve();
53-
}
54-
);
51+
});
5552
});
5653
});
54+
55+
after(() => {
56+
process.chdir(rootDir);
57+
build.clean(['node', 'run-clean', sandbox]);
58+
process.chdir(cwd);
59+
});
5760
});
61+
62+
function lernaBootstrap(scope) {
63+
const cmd = new lerna.BootstrapCommand('', {
64+
scope: scope,
65+
loglevel: 'silent',
66+
});
67+
return cmd.run();
68+
}

0 commit comments

Comments
 (0)