Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add import command #2580

Merged
merged 1 commit into from
Feb 14, 2017
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
102 changes: 102 additions & 0 deletions __tests__/commands/import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* @flow */

import type {CLIFunctionReturn} from '../../src/types.js';
import * as reporters from '../../src/reporters/index.js';
import * as importCmd from '../../src/cli/commands/import.js';
import Lockfile from '../../src/lockfile/wrapper.js';
import * as fs from '../../src/util/fs.js';
import {run as buildRun} from './_helpers.js';

const path = require('path');

const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'import');

const runImport = buildRun.bind(
null,
reporters.BufferReporter,
fixturesLoc,
(args, flags, config, reporter): CLIFunctionReturn => {
return importCmd.run(config, reporter, flags, args);
},
);

const reporterType = (reporter, type) => reporter.getBuffer().filter((d) => d.type === type);

const reporterErrors = (reporter) => reporter.getBuffer().filter((d) => d.error);

const checkReporter = (reporter) => {
expect(reporterErrors(reporter)).toEqual([]);
expect(reporterType(reporter, 'info')).toEqual([]);
};

const checkLockfile = async (config, reporter) => {
const lockfile = await Lockfile.fromDirectory(config.cwd, reporter);
const imported = await fs.readFile(path.join(config.cwd, 'yarn.lock.import'));
expect(lockfile.source).toEqual(imported);
};

const checkReporterAndLockfile = async (config, reporter) => {
checkReporter(reporter);
await checkLockfile(config, reporter);
checkReporter(reporter);
};

test.concurrent('import shallow deps', () => {
return runImport([], {}, 'shallow', checkReporterAndLockfile);
});

test.concurrent('import deep deps', () => {
return runImport([], {}, 'deep', checkReporterAndLockfile);
});

test.concurrent('import shallow dev deps', () => {
return runImport([], {}, 'shallow-dev', checkReporterAndLockfile);
});

test.concurrent('import github deps', () => {
return runImport([], {}, 'github', checkReporterAndLockfile);
});

test.concurrent('import file deps', () => {
return runImport([], {}, 'file', checkReporterAndLockfile);
});

test.concurrent('throw on missing dev deps deps', async () => {
let thrown = false;
try {
await runImport([], {}, 'missing-dev');
} catch (err) {
thrown = true;
}
expect(thrown).toBeTruthy();
});

test.concurrent('import missing dev deps in production', () => {
return runImport([], {production: true}, 'missing-dev', async (config, reporter) => {
expect(reporterErrors(reporter).length).toEqual(1);
expect(reporterType(reporter, 'warning').length).toEqual(1);
await checkLockfile(config, reporter);
expect(reporterErrors(reporter).length).toEqual(1);
expect(reporterType(reporter, 'warning').length).toEqual(1);
});
});

test.concurrent('import missing opt deps', () => {
return runImport([], {}, 'missing-opt', async (config, reporter) => {
expect(reporterErrors(reporter).length).toEqual(1);
expect(reporterType(reporter, 'warning').length).toEqual(1);
await checkLockfile(config, reporter);
expect(reporterErrors(reporter).length).toEqual(1);
expect(reporterType(reporter, 'warning').length).toEqual(1);
});
});

test.concurrent('throw on locked deps', async () => {
let thrown = false;
try {
await runImport([], {}, 'locked');
} catch (err) {
thrown = true;
}
expect(thrown).toBeTruthy();
});
261 changes: 261 additions & 0 deletions __tests__/fixtures/import/deep/node_modules/commander/History.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions __tests__/fixtures/import/deep/node_modules/commander/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading