Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/contentstack-clone/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require": ["test/helpers/init.js", "ts-node/register", "source-map-support/register", "test/helpers/mocha-root-hooks.js"],
"require": ["test/helpers/stub-ora.js", "test/helpers/init.js", "ts-node/register", "source-map-support/register", "test/helpers/mocha-root-hooks.js"],
"watch-extensions": [
"ts"
],
Expand Down
55 changes: 55 additions & 0 deletions packages/contentstack-clone/test/helpers/stub-ora.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Replace `ora` with a no-op spinner before any test file loads application code.
* Real ora keeps timers / TTY animation and can leave the process hanging after tests
* (e.g. "Fetching Branches") even when assertions pass.
*
* Must be listed first in `.mocharc.json` `require` so it runs before `ts-node/register`
* and test imports.
*/
'use strict';

const oraPath = require.resolve('ora');
const originalOra = require(oraPath);

function createNoopSpinner() {
const api = {
start() {
return api;
},
stop() {
return api;
},
succeed() {
return api;
},
fail() {
return api;
},
clear() {
return api;
},
text: '',
isSpinning: false,
};
return api;
}

function noopOraFactory() {
return createNoopSpinner();
}

if (typeof originalOra.promise === 'function') {
noopOraFactory.promise = async function (action, options) {
if (!action || typeof action.then !== 'function') {
throw new TypeError('Parameter `action` must be a Promise');
}
try {
await action;
return createNoopSpinner();
} catch {
return createNoopSpinner();
}
};
}

require.cache[oraPath].exports = noopOraFactory;
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('CloneHandler - Stack', () => {
stack: sandbox.stub(),
};
handler.setClient(mockClient);
sandbox.stub(handler, 'displayBackOptionMessage');
});

afterEach(() => {
Expand Down Expand Up @@ -79,7 +80,6 @@ describe('CloneHandler - Stack', () => {
});
});
const inquirerStub = sandbox.stub(inquirer, 'prompt').resolves({ stack: 'TestStack' });
const displayBackOptionMessageStub = sandbox.stub(handler, 'displayBackOptionMessage');

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

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

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

getStackStub.restore();
Expand Down
Loading