Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Refactor specs to use shared package helper
Browse files Browse the repository at this point in the history
 🐿 v2.10.0
  • Loading branch information
i-like-robots committed Dec 7, 2018
1 parent 8941bb1 commit 64c637b
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 82 deletions.
10 changes: 0 additions & 10 deletions src/sort-packages.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
const toposort = require('toposort');

const collateDependencies = (manifest) => {
// TODO: refactor into package class
return Object.keys({
...manifest.dependencies,
...manifest.devDependencies,
...manifest.peerDependencies,
...manifest.optionalDependencies
});
};

module.exports = (reverse = false, packages = []) => {
const packageNames = new Set(packages.map((pkg) => pkg.name));

Expand Down
10 changes: 10 additions & 0 deletions test/helpers/create-package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const Package = require('../../src/package');

module.exports = (name, options = {}) => {
const manifest = { name, ...options };
const instance = new Package(manifest, `/Path/to/${name}`);

instance.writeManifest = jest.fn();

return instance;
};
2 changes: 1 addition & 1 deletion test/src/package.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('src/package', () => {
expect(instance.allDependencies).toBeInstanceOf(Array);
expect(instance.allDependencies.length).toEqual(4);
});
})
});

describe('#writeManifest', () => {
beforeEach(() => {
Expand Down
50 changes: 19 additions & 31 deletions test/src/sort-packages.spec.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
const subject = require('../../src/sort-packages');
const createPackage = require('../helpers/create-package');

const fixture = Object.freeze([
{
name: 'foo',
manifest: {
dependencies: {
qux: '0.0.0'
}
const fixture = [
createPackage('foo', {
dependencies: {
qux: '0.0.0'
}
},
{
name: 'bar',
manifest: {
dependencies: {
baz: '0.0.0'
}
}),
createPackage('bar', {
dependencies: {
baz: '0.0.0'
}
},
{
name: 'baz',
manifest: {
dependencies: {
foo: '0.0.0',
qux: '0.0.0'
}
},
},
{
name: 'qux',
manifest: {
dependencies: {
}
}),
createPackage('baz', {
dependencies: {
foo: '0.0.0',
qux: '0.0.0'
}
}
]);
}),
createPackage('qux', {
dependencies: {}
})
];

describe('src/sort-packages', () => {
it('returns a new array', () => {
Expand Down
8 changes: 1 addition & 7 deletions test/src/tasks/exec.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ const mockRun = jest.fn();
jest.mock('../../../src/run-package', () => mockRun);

const { task: subject } = require('../../../src/tasks/exec');

const createPackage = (name) => (
{
name,
location: `/Path/to/${name}`
}
);
const createPackage = require('../../helpers/create-package');

describe('src/tasks/exec', () => {
const packages = [
Expand Down
9 changes: 1 addition & 8 deletions test/src/tasks/publish.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ const mockRun = jest.fn();
jest.mock('../../../src/run-package', () => mockRun);

const { task: subject } = require('../../../src/tasks/publish');

const createPackage = (name, options = {}) => (
{
name,
location: `/Path/to/${name}`,
...options
}
);
const createPackage = require('../../helpers/create-package');

describe('src/tasks/publish', () => {
const packages = [
Expand Down
15 changes: 4 additions & 11 deletions test/src/tasks/run.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@ const mockRun = jest.fn();
jest.mock('../../../src/run-package', () => mockRun);

const { task: subject } = require('../../../src/tasks/run');

const createPackage = (name, options = {}) => (
{
name,
location: `/Path/to/${name}`,
...options
}
);
const createPackage = require('../../helpers/create-package');

describe('src/tasks/run', () => {
const packages = [
createPackage('foo', { manifest: { scripts: { test: '' } } }),
createPackage('bar', { manifest: { scripts: { test: '' } } }),
createPackage('baz', { manifest: {} }),
createPackage('foo', { scripts: { test: '' } }),
createPackage('bar', { scripts: { test: '' } }),
createPackage('baz', { scripts: {} }),
];

const command = 'test';
Expand Down
8 changes: 1 addition & 7 deletions test/src/tasks/script.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ const mockRun = jest.fn();
jest.mock('../../../src/run-package', () => mockRun);

const { task: subject } = require('../../../src/tasks/script');

const createPackage = (name) => (
{
name,
location: `/Path/to/${name}`
}
);
const createPackage = require('../../helpers/create-package');

describe('src/tasks/script', () => {
const packages = [
Expand Down
8 changes: 1 addition & 7 deletions test/src/tasks/version.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ const mockRun = jest.fn();
jest.mock('../../../src/run-package', () => mockRun);

const { task: subject } = require('../../../src/tasks/version');

const createPackage = (name) => (
{
name,
location: `/Path/to/${name}`
}
);
const createPackage = require('../../helpers/create-package');

describe('src/tasks/version', () => {
const packages = [
Expand Down

0 comments on commit 64c637b

Please sign in to comment.