bit-bin
Version:
<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b
135 lines (128 loc) • 5.04 kB
JavaScript
function _chai() {
const data = require("chai");
_chai = function () {
return data;
};
return data;
}
function _linkContent() {
const data = require("./link-content");
_linkContent = function () {
return data;
};
return data;
}
describe('getLinkContent', () => {
it('should generate content for simple js file', () => {
const result = (0, _linkContent().getLinkToFileContent)('my-path.js');
(0, _chai().expect)(result).to.equal("module.exports = require('./my-path');");
});
it('should generate correct content for npm vue package without .vue extension', () => {
const result = (0, _linkContent().getLinkToPackageContent)('../../../src/pages/my-page.vue', '@bit/david.scope.components.vue-page');
(0, _chai().expect)(result).to.have.string("module.exports = require('@bit/david.scope.components.vue-page');");
(0, _chai().expect)(result).to.not.have.string("module.exports = require('@bit/david.scope.components.vue-page.vue');");
});
describe('es6 with link files', () => {
const exportDefaultForm = 'exports.default =';
const exportNonDefaultForm = 'exports.isString =';
const importDefaultForm = "= _isString && _isString.hasOwnProperty('default') ? _isString.default : _isString;";
const importNonDefaultForm = '= _isString.isString';
describe('mainFile is not default and linkFile is default', () => {
let linkContent;
before(() => {
const importSpecifier = [{
mainFile: {
isDefault: false,
name: 'isString'
},
linkFile: {
isDefault: true,
name: 'isString'
}
}];
linkContent = (0, _linkContent().getLinkToFileContent)('is-string.js', importSpecifier);
});
it('the generated link should export non-default', () => {
(0, _chai().expect)(linkContent).to.have.string(exportNonDefaultForm);
(0, _chai().expect)(linkContent).to.not.have.string(exportDefaultForm);
});
it('the generated link should import default', () => {
(0, _chai().expect)(linkContent).to.have.string(importDefaultForm);
(0, _chai().expect)(linkContent).to.not.have.string(importNonDefaultForm);
});
});
describe('mainFile and linkFile are both default', () => {
let linkContent;
before(() => {
const importSpecifier = [{
mainFile: {
isDefault: true,
name: 'isString'
},
linkFile: {
isDefault: true,
name: 'isString'
}
}];
linkContent = (0, _linkContent().getLinkToFileContent)('is-string.js', importSpecifier);
});
it('the generated link should export default', () => {
(0, _chai().expect)(linkContent).to.have.string(exportDefaultForm);
(0, _chai().expect)(linkContent).to.not.have.string(exportNonDefaultForm);
});
it('the generated link should import default', () => {
(0, _chai().expect)(linkContent).to.have.string(importDefaultForm);
(0, _chai().expect)(linkContent).to.not.have.string(importNonDefaultForm);
});
});
describe('mainFile and linkFile are both non-default', () => {
let linkContent;
before(() => {
const importSpecifier = [{
mainFile: {
isDefault: false,
name: 'isString'
},
linkFile: {
isDefault: false,
name: 'isString'
}
}];
linkContent = (0, _linkContent().getLinkToFileContent)('is-string.js', importSpecifier);
});
it('the generated link should export non-default', () => {
(0, _chai().expect)(linkContent).to.have.string(exportNonDefaultForm);
(0, _chai().expect)(linkContent).to.not.have.string(exportDefaultForm);
});
it('the generated link should import non-default', () => {
(0, _chai().expect)(linkContent).to.have.string(importNonDefaultForm);
(0, _chai().expect)(linkContent).to.not.have.string(importDefaultForm);
});
});
describe('mainFile is default and link file is not default', () => {
let linkContent;
before(() => {
const importSpecifier = [{
mainFile: {
isDefault: true,
name: 'isString'
},
linkFile: {
isDefault: false,
name: 'isString'
}
}];
linkContent = (0, _linkContent().getLinkToFileContent)('is-string.js', importSpecifier);
});
it('the generated link should export default', () => {
(0, _chai().expect)(linkContent).to.have.string(exportDefaultForm);
(0, _chai().expect)(linkContent).to.not.have.string(exportNonDefaultForm);
});
it('the generated link should import non-default', () => {
(0, _chai().expect)(linkContent).to.have.string(importNonDefaultForm);
(0, _chai().expect)(linkContent).to.not.have.string(importDefaultForm);
});
});
});
});
;