Skip to content

Commit 5329449

Browse files
authored
Merge pull request #91 from contentstack/fix/DX-5330
fixed the test report generation issue
2 parents 6307355 + 881dd98 commit 5329449

3 files changed

Lines changed: 59 additions & 5 deletions

File tree

packages/contentstack-clone/.mocharc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"require": ["test/helpers/init.js", "ts-node/register", "source-map-support/register", "test/helpers/mocha-root-hooks.js"],
2+
"require": ["test/helpers/stub-ora.js", "test/helpers/init.js", "ts-node/register", "source-map-support/register", "test/helpers/mocha-root-hooks.js"],
33
"watch-extensions": [
44
"ts"
55
],
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Replace `ora` with a no-op spinner before any test file loads application code.
3+
* Real ora keeps timers / TTY animation and can leave the process hanging after tests
4+
* (e.g. "Fetching Branches") even when assertions pass.
5+
*
6+
* Must be listed first in `.mocharc.json` `require` so it runs before `ts-node/register`
7+
* and test imports.
8+
*/
9+
'use strict';
10+
11+
const oraPath = require.resolve('ora');
12+
const originalOra = require(oraPath);
13+
14+
function createNoopSpinner() {
15+
const api = {
16+
start() {
17+
return api;
18+
},
19+
stop() {
20+
return api;
21+
},
22+
succeed() {
23+
return api;
24+
},
25+
fail() {
26+
return api;
27+
},
28+
clear() {
29+
return api;
30+
},
31+
text: '',
32+
isSpinning: false,
33+
};
34+
return api;
35+
}
36+
37+
function noopOraFactory() {
38+
return createNoopSpinner();
39+
}
40+
41+
if (typeof originalOra.promise === 'function') {
42+
noopOraFactory.promise = async function (action, options) {
43+
if (!action || typeof action.then !== 'function') {
44+
throw new TypeError('Parameter `action` must be a Promise');
45+
}
46+
try {
47+
await action;
48+
return createNoopSpinner();
49+
} catch {
50+
return createNoopSpinner();
51+
}
52+
};
53+
}
54+
55+
require.cache[oraPath].exports = noopOraFactory;

packages/contentstack-clone/test/lib/util/clone-handler.stack.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe('CloneHandler - Stack', () => {
3838
stack: sandbox.stub(),
3939
};
4040
handler.setClient(mockClient);
41+
sandbox.stub(handler, 'displayBackOptionMessage');
4142
});
4243

4344
afterEach(() => {
@@ -79,7 +80,6 @@ describe('CloneHandler - Stack', () => {
7980
});
8081
});
8182
const inquirerStub = sandbox.stub(inquirer, 'prompt').resolves({ stack: 'TestStack' });
82-
const displayBackOptionMessageStub = sandbox.stub(handler, 'displayBackOptionMessage');
8383

8484
const result = await handler.handleStackSelection({
8585
org: { Organization: 'TestOrg' },
@@ -90,7 +90,7 @@ describe('CloneHandler - Stack', () => {
9090
expect((handler as any).config.sourceStackName).to.equal('TestStack');
9191
expect((handler as any).config.source_stack).to.equal('test-stack-key');
9292
expect((handler as any).master_locale).to.equal('en-us');
93-
expect(displayBackOptionMessageStub.calledOnce).to.be.true;
93+
expect((handler.displayBackOptionMessage as sinon.SinonStub).calledOnce).to.be.true;
9494
expect(getStackStub.calledOnce).to.be.true;
9595

9696
getStackStub.restore();
@@ -108,7 +108,6 @@ describe('CloneHandler - Stack', () => {
108108
});
109109
});
110110
const inquirerStub = sandbox.stub(inquirer, 'prompt').resolves({ stack: 'TestStack' });
111-
const displayBackOptionMessageStub = sandbox.stub(handler, 'displayBackOptionMessage');
112111

113112
const result = await handler.handleStackSelection({
114113
org: { Organization: 'TestOrg' },
@@ -118,7 +117,7 @@ describe('CloneHandler - Stack', () => {
118117
expect(result).to.have.property('stack', 'TestStack');
119118
expect((handler as any).config.target_stack).to.equal('test-stack-key');
120119
expect((handler as any).config.destinationStackName).to.equal('TestStack');
121-
expect(displayBackOptionMessageStub.calledOnce).to.be.true;
120+
expect((handler.displayBackOptionMessage as sinon.SinonStub).calledOnce).to.be.true;
122121
expect(getStackStub.calledOnce).to.be.true;
123122

124123
getStackStub.restore();

0 commit comments

Comments
 (0)