@teambit/checkout
Version:
169 lines (164 loc) • 5.28 kB
JavaScript
;
function _chai() {
const data = require("chai");
_chai = function () {
return data;
};
return data;
}
function _fsExtra() {
const data = _interopRequireDefault(require("fs-extra"));
_fsExtra = function () {
return data;
};
return data;
}
function _harmonyTesting() {
const data = require("@teambit/harmony.testing.load-aspect");
_harmonyTesting = function () {
return data;
};
return data;
}
function _snapping() {
const data = require("@teambit/snapping");
_snapping = function () {
return data;
};
return data;
}
function _workspace() {
const data = require("@teambit/workspace");
_workspace = function () {
return data;
};
return data;
}
function _workspaceTesting() {
const data = require("@teambit/workspace.testing.mock-workspace");
_workspaceTesting = function () {
return data;
};
return data;
}
function _componentTesting() {
const data = require("@teambit/component.testing.mock-components");
_componentTesting = function () {
return data;
};
return data;
}
function _lister() {
const data = require("@teambit/lister");
_lister = function () {
return data;
};
return data;
}
function _checkout() {
const data = require("./checkout.aspect");
_checkout = function () {
return data;
};
return data;
}
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/// <reference types="chai-fs" />
(0, _chai().use)(require('chai-fs'));
describe('CheckoutAspect', function () {
this.timeout(0);
describe('checkout reset when the component files were deleted', () => {
let checkout;
let workspace;
let workspaceData;
let compDir;
let compId;
before(async () => {
workspaceData = (0, _workspaceTesting().mockWorkspace)();
const {
workspacePath
} = workspaceData;
const compsDir = await (0, _componentTesting().mockComponents)(workspacePath);
const snapping = await (0, _harmonyTesting().loadAspect)(_snapping().SnappingAspect, workspacePath);
await snapping.tag({
ids: ['comp1'],
build: false,
ignoreIssues: 'MissingManuallyConfiguredPackages'
});
const {
id,
dir
} = compsDir[0];
compId = id;
compDir = dir;
await _fsExtra().default.remove(dir);
// an intermediate step, check sure that the dir is not there and the component is invalid
(0, _chai().expect)(dir).to.not.be.a.path();
workspace = await (0, _harmonyTesting().loadAspect)(_workspace().WorkspaceAspect, workspacePath);
const {
components,
invalidComponents
} = await workspace.componentLoader.getMany([id], undefined, false);
(0, _chai().expect)(components).to.have.lengthOf(0);
(0, _chai().expect)(invalidComponents).to.have.lengthOf(1);
checkout = await (0, _harmonyTesting().loadAspect)(_checkout().CheckoutAspect, workspacePath);
await checkout.checkout({
reset: true,
ids: [id]
});
});
after(async () => {
await (0, _workspaceTesting().destroyWorkspace)(workspaceData);
});
it('should bring the files back', () => {
(0, _chai().expect)(compDir).to.be.a.path();
});
it('the workspace should get the component as a valid component', async () => {
workspace = await (0, _harmonyTesting().loadAspect)(_workspace().WorkspaceAspect, workspaceData.workspacePath);
const {
components,
invalidComponents
} = await workspace.componentLoader.getMany([compId], undefined, false);
(0, _chai().expect)(components).to.have.lengthOf(1);
(0, _chai().expect)(invalidComponents).to.have.lengthOf(0);
});
});
describe('checkout to an ancestor', () => {
let workspaceData;
let harmony;
before(async () => {
workspaceData = (0, _workspaceTesting().mockWorkspace)();
const {
workspacePath
} = workspaceData;
await (0, _componentTesting().mockComponents)(workspacePath, {
numOfComponents: 2
});
harmony = await (0, _harmonyTesting().loadManyAspects)([_snapping().SnappingAspect, _lister().ListerAspect, _checkout().CheckoutAspect], workspacePath);
const snapping = harmony.get(_snapping().SnappingAspect.id);
const tagOpts = {
build: false,
ignoreIssues: 'MissingManuallyConfiguredPackages',
unmodified: true
};
await snapping.tag(tagOpts); // 0.0.1
await snapping.tag(tagOpts); // 0.0.2
await snapping.tag(tagOpts); // 0.0.3
await snapping.tag(tagOpts); // 0.0.4
const checkout = harmony.get(_checkout().CheckoutAspect.id);
await checkout.checkoutByCLIValues('', {
ancestor: 2,
all: true,
skipNpmInstall: true
});
});
it('should checkout according to the number of generations specified', async () => {
const lister = harmony.get(_lister().ListerAspect.id);
const list = await lister.localList();
(0, _chai().expect)(list).to.have.lengthOf(2);
(0, _chai().expect)(list[0].currentlyUsedVersion).to.equal('0.0.2');
(0, _chai().expect)(list[1].currentlyUsedVersion).to.equal('0.0.2');
});
});
});
//# sourceMappingURL=checkout.spec.js.map