question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Upgrading to 0.8.0 will break imports from outside of the test's directory

See original GitHub issue

If you are reporting a bug, please fill in below. Otherwise feel free to remove this template entirely.

Can you reproduce the problem with latest npm?

Yes. npm 4.0.3

Description

After upgrading to react-scripts 0.8.0 tests that import files or utilities from outside the current testing directory return 'test-file-stub' as the default (and undefined, of course, for any destructured imports).

Expected behavior

In the prior version of react-scripts, importing utilities into tests worked as expected. If you had a utils directory in your src and you imported it into a test running in another directory in src, you would have access to to the imported code. For example:

src
├── utils
│   └── range.js
└── parsers
    └── books.js
    └── books.test.js

Where in the test file books.test.js:

import parser from './book';
import range from '../utils/range';

console.log(parser);
console.log(range);

const generateFakeBook = (n) => ({title: `Hello ${n}`, author: 'Who Ever'});

it('should parse the book', () => {
  for(let n in range(10)) {
    expect(
      parser(generateFakeBook(n))
    ).toEqual({
      title: '', 
      author: ''
    });
  }
});

The test would run and if you logged out the range function, you would see that it was the function you expected. In the prior release, you could make use of your utility functions in your tests as well as import other items for assisting in your testing.

Actual behavior

If you log out range, you’ll see test-file-stub. This happens with any import outside of the directory with the test.

Environment

Run these commands in the project folder and fill in their results:

  1. npm ls react-scripts (if you haven’t ejected):

react-scripts@0.8.0

  1. node -v:

v7.2.0

  1. npm -v:

4.0.3

Then, specify:

  1. Operating system: Mac OS X 10.11.6

  2. Browser and version: Firefox 50

Reproducible Demo

I’ve created 2 versions to show the behavior in 0.7.0 and 0.8.0 and included them in this repo: https://github.com/adregan/create-react-app-issue

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
adregancommented, Dec 4, 2016

Thanks for getting the hot fix out so quickly. 👍

0reactions
kentcdoddscommented, Dec 4, 2016

Yes, thank you very much! Really appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrading Pinot with confidence - Apache Pinot Docs
Pinot has unit and integration tests that verify that the system can work well as long as all components are in the same...
Read more >
Python Nose Import Error - Stack Overflow
I have a situation where tests work if init.py in root directory - however, I need that file to be there, and import...
Read more >
Upgrading to newer versions of Roundup
Critical documentation on how to upgrade the Roundup Issue Tracker. Actions that must or can be taken when upgrading from one version to...
Read more >
migration guide - Dagster Docs
When new releases include breaking changes or deprecations, this document ... Here is a guide to migrating from the legacy APIs to the...
Read more >
Testing SKAMPI — SKA MVP Integration 0.8.0-pi#10 ...
SKAMPI should be seen as a testing facility where the final stage of developed software is run before delivery and connection with real...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found