Skip to content

Commit a1549ce

Browse files
author
Maël Nison
committed
Adds tests
1 parent 4c6718a commit a1549ce

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

__tests__/integration.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,58 @@ test('--mutex network', async () => {
7373
]);
7474
});
7575

76+
// Windows doesn't have the "echo" utility
77+
// Since this feature isn't platform-specific, running them on OSX and Linux only should be fine
78+
if (process.platform !== 'win32') {
79+
test('yarn run <script> --opt', async () => {
80+
const cwd = await makeTemp();
81+
82+
await fs.writeFile(
83+
path.join(cwd, 'package.json'),
84+
JSON.stringify({
85+
scripts: {echo: 'echo'},
86+
}),
87+
);
88+
89+
const command = path.resolve(__dirname, '../bin/yarn');
90+
const options = {cwd};
91+
92+
const {stderr: stderr, stdout: stdout} = execa(command, ['run', 'echo', '--opt'], options);
93+
94+
const stdoutPromise = misc.consumeStream(stdout);
95+
const stderrPromise = misc.consumeStream(stderr);
96+
97+
const [stdoutOutput, stderrOutput] = await Promise.all([stdoutPromise, stderrPromise]);
98+
99+
expect(stdoutOutput.toString().trim()).toEqual('--opt');
100+
expect(stderrOutput.toString()).not.toMatch(/Using -- to pass arguments to your scripts isn't required anymore/);
101+
});
102+
103+
test('yarn run <script> -- --opt', async () => {
104+
const cwd = await makeTemp();
105+
106+
await fs.writeFile(
107+
path.join(cwd, 'package.json'),
108+
JSON.stringify({
109+
scripts: {echo: 'echo'},
110+
}),
111+
);
112+
113+
const command = path.resolve(__dirname, '../bin/yarn');
114+
const options = {cwd};
115+
116+
const {stderr: stderr, stdout: stdout} = execa(command, ['run', 'echo', '--', '--opt'], options);
117+
118+
const stdoutPromise = misc.consumeStream(stdout);
119+
const stderrPromise = misc.consumeStream(stderr);
120+
121+
const [stdoutOutput, stderrOutput] = await Promise.all([stdoutPromise, stderrPromise]);
122+
123+
expect(stdoutOutput.toString().trim()).toEqual('--opt');
124+
expect(stderrOutput.toString()).toMatch(/Using -- to pass arguments to your scripts isn't required anymore/);
125+
});
126+
}
127+
76128
test('cache folder fallback', async () => {
77129
const cwd = await makeTemp();
78130
const cacheFolder = path.join(cwd, '.cache');

src/cli/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export function main({
114114
// we using "yarn <script> -abc" or "yarn run <script> -abc", we want -abc to be script options, not yarn options
115115
if (command === commands.run) {
116116
if (endArgs.length === 0) {
117-
endArgs = ['--', ... args.splice(1, args.length)];
117+
endArgs = ['--', ...args.splice(1, args.length)];
118118
} else {
119119
warnAboutRunDashDash = true;
120120
}

src/reporters/lang/en.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ const messages = {
188188

189189
execMissingCommand: 'Missing command name.',
190190

191-
dashDashDeprecation: "Using -- to pass arguments to your scripts isn't required anymore. Doing this may cause issues in future versions.",
191+
dashDashDeprecation:
192+
"Using -- to pass arguments to your scripts isn't required anymore. Doing this may cause issues in future versions.",
192193
commandNotSpecified: 'No command specified.',
193194
binCommands: 'Commands available from binary scripts: ',
194195
possibleCommands: 'Project commands',

0 commit comments

Comments
 (0)