Skip to content

Commit

Permalink
Chore: Free tests from FORCE_COLOR environment variable dependency (#…
Browse files Browse the repository at this point in the history
…4381)

**Summary**

FORCE_COLOR environment variable allows to force yarn to use
colors. This makes some of tests fail because of comparing
colorized output with plain strings.

For example, if you run a test in environment where
FORCE_COLOR is set you get this failure:

```
 FAIL  __tests__\index.js
  ● should add package
    expect(received).toEqual(expected)
    Expected value to equal:
      "success Saved lockfile."
    Received:
success Saved lockfile."
```

**Test plan**

Run tests in an environment where `FORCE_COLOR` is enabled. They should pass.
  • Loading branch information
hron authored and BYK committed Sep 18, 2017
1 parent 0ee1c55 commit 3124c91
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 5 additions & 4 deletions __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ async function execCommand(
const cacheDir = path.join(workingDir, '.yarn-cache');

return new Promise((resolve, reject) => {
const cleanedEnv = {...process.env};
cleanedEnv['YARN_SILENT'] = 0;
delete cleanedEnv['FORCE_COLOR'];

exec(
`node "${yarnBin}" --cache-folder="${cacheDir}" ${cmd} ${args.join(' ')}`,
{
cwd: workingDir,
env: {
...process.env,
YARN_SILENT: 0,
},
env: cleanedEnv,
},
(error, stdout) => {
if (error) {
Expand Down
5 changes: 5 additions & 0 deletions __tests__/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ const PORT_RANGE = MAX_PORT_NUM - MIN_PORT_NUM;
const getRandomPort = () => Math.floor(Math.random() * PORT_RANGE) + MIN_PORT_NUM;

async function runYarn(args: Array<string> = [], options: Object = {}): Promise<Array<Buffer>> {
if (!options['env']) {
options['env'] = {...process.env};
options['extendEnv'] = false;
}
delete options['env']['FORCE_COLOR'];
const {stdout, stderr} = await execa(path.resolve(__dirname, '../bin/yarn'), args, options);

return [stdout, stderr];
Expand Down
9 changes: 5 additions & 4 deletions __tests__/lifecycle-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ async function execCommand(cmd: string, packageName: string, env = process.env):
await fs.copy(srcPackageDir, packageDir, new NoopReporter());

return new Promise((resolve, reject) => {
const cleanedEnv = {...env};
cleanedEnv['YARN_SILENT'] = 0;
delete cleanedEnv['FORCE_COLOR'];

exec(
`node "${yarnBin}" ${cmd}`,
{
cwd: packageDir,
env: {
...env,
YARN_SILENT: 0,
},
env: cleanedEnv,
},
(err, stdout) => {
if (err) {
Expand Down

0 comments on commit 3124c91

Please sign in to comment.