-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some tests for link/unlink command (#3293)
* add tests for link command * add tests for unlink command * fix some lint issues
- Loading branch information
Showing
8 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* @flow */ | ||
|
||
import {run as buildRun} from './_helpers.js'; | ||
import {run as link} from '../../src/cli/commands/link.js'; | ||
import {ConsoleReporter} from '../../src/reporters/index.js'; | ||
import type {CLIFunctionReturn} from '../../src/types.js'; | ||
import mkdir from './../_temp.js'; | ||
import * as fs from '../../src/util/fs.js'; | ||
|
||
const path = require('path'); | ||
|
||
const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'link'); | ||
const runLink = buildRun.bind( | ||
null, | ||
ConsoleReporter, | ||
fixturesLoc, | ||
(args, flags, config, reporter): CLIFunctionReturn => { | ||
return link(config, reporter, flags, args); | ||
}, | ||
); | ||
|
||
test.concurrent('creates folder in linkFolder', async (): Promise<void> => { | ||
const linkFolder = await mkdir('link-folder'); | ||
await runLink([], {linkFolder}, 'package-with-name', async (config, reporter): Promise<void> => { | ||
const existed = await fs.exists(path.join(linkFolder, 'a-package')); | ||
expect(existed).toEqual(true); | ||
}); | ||
}); | ||
|
||
test.concurrent('throws error if package.json does not have name', async (): Promise<void> => { | ||
const linkFolder = await mkdir('link-folder'); | ||
const reporter = new ConsoleReporter({}); | ||
|
||
try { | ||
await runLink([], {linkFolder}, 'package-no-name', () => {}); | ||
} catch (err) { | ||
expect(err.message).toContain(reporter.lang('unknownPackageName')); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* @flow */ | ||
|
||
import {run as buildRun} from './_helpers.js'; | ||
import {run as link} from '../../src/cli/commands/link.js'; | ||
import {run as unlink} from '../../src/cli/commands/unlink.js'; | ||
import {ConsoleReporter} from '../../src/reporters/index.js'; | ||
import type {CLIFunctionReturn} from '../../src/types.js'; | ||
import mkdir from './../_temp.js'; | ||
import * as fs from '../../src/util/fs.js'; | ||
|
||
const path = require('path'); | ||
|
||
const fixturesLoc = path.join(__dirname, '..', 'fixtures', 'link'); | ||
const runLink = buildRun.bind( | ||
null, | ||
ConsoleReporter, | ||
fixturesLoc, | ||
(args, flags, config, reporter): CLIFunctionReturn => { | ||
return link(config, reporter, flags, args); | ||
}, | ||
); | ||
|
||
const runUnlink = buildRun.bind( | ||
null, | ||
ConsoleReporter, | ||
fixturesLoc, | ||
(args, flags, config, reporter): CLIFunctionReturn => { | ||
return unlink(config, reporter, flags, args); | ||
}, | ||
); | ||
|
||
test.concurrent('creates folder in linkFolder', async (): Promise<void> => { | ||
const linkFolder = await mkdir('link-folder'); | ||
|
||
await runLink([], {linkFolder}, 'package-with-name', async (config, reporter): Promise<void> => { | ||
const existed = await fs.exists(path.join(linkFolder, 'a-package')); | ||
expect(existed).toEqual(true); | ||
}); | ||
|
||
await runUnlink([], {linkFolder}, 'package-with-name', async (config, reporter): Promise<void> => { | ||
const existed = await fs.exists(path.join(linkFolder, 'a-package')); | ||
expect(existed).toEqual(false); | ||
}); | ||
}); | ||
|
||
test.concurrent('throws error if package.json does not have name', async (): Promise<void> => { | ||
const linkFolder = await mkdir('link-folder'); | ||
const reporter = new ConsoleReporter({}); | ||
|
||
try { | ||
await runUnlink([], {linkFolder}, 'package-no-name', () => {}); | ||
} catch (err) { | ||
expect(err.message).toContain(reporter.lang('unknownPackageName')); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
foobar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "bar", | ||
"version": "0.0.0", | ||
"main": "index.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "a-package", | ||
"dependencies": { | ||
"foo": "file:bar" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
"foo@file:bar": | ||
version "0.0.0" |