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

Correctly lookup assets when using a relative build directory #5163

Merged
merged 4 commits into from
Sep 29, 2018

Conversation

Timer
Copy link
Contributor

@Timer Timer commented Sep 28, 2018

Fixes #5162

@Timer Timer added this to the 2.0.0 milestone Sep 28, 2018
@gaearon
Copy link
Contributor

gaearon commented Sep 28, 2018

e2e would be nice

@Timer
Copy link
Contributor Author

Timer commented Sep 29, 2018

Example broken e2e:

joes-mbp:create-react-app joe$ ./node_modules/.bin/jest --config fixtures/smoke/jest.config.js fixtures/smoke/relative-paths/
 FAIL  fixtures/smoke/relative-paths/index.test.js (22.318s)
  relative paths
    ✕ builds in production (21559ms)
    ○ skipped 1 test

  ● relative paths › builds in production

    expect(received).toBe(expected) // Object.is equality

    Expected: "/private/var/folders/c3/vytj6_h56b77f_g72smntm3m0000gn/T/72a73262107e4b983270278cf537ee30/build/static/media/logo.83ec6b6a.svg"
    Received: "/private/var/folders/c3/vytj6_h56b77f_g72smntm3m0000gn/T/72a73262107e4b983270278cf537ee30/build/static/css/static/media/logo.83ec6b6a.svg"

      31 |       .exec(fs.readFileSync(cssFile, 'utf8'))
      32 |       .pop();
    > 33 |     expect(path.resolve(path.join(path.dirname(cssFile), desiredPath))).toBe(
         |                                                                         ^
      34 |       path.resolve(svgFile)
      35 |     );
      36 |   });

      at Object.toBe (relative-paths/index.test.js:33:73)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 skipped, 2 total
Snapshots:   0 total
Time:        22.367s, estimated 23s
Ran all test suites matching /fixtures\/smoke\/relative-paths\//i.
joes-mbp:create-react-app joe$

const buildDir = path.join(global.testDirectory, 'build');
const cssFile = path.join(
buildDir,
globby.sync('**/*.css', { cwd: buildDir }).pop()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This future proofs our file structure.

const desiredPath = /url\((.+?)\)/
.exec(fs.readFileSync(cssFile, 'utf8'))
.pop();
expect(path.resolve(path.join(path.dirname(cssFile), desiredPath))).toBe(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolves it as the browser would.

@Timer Timer merged commit 42026a0 into facebook:master Sep 29, 2018
@Timer Timer deleted the hotfix/relative-paths branch September 29, 2018 03:03
zmitry pushed a commit to zmitry/create-react-app that referenced this pull request Sep 30, 2018
…ok#5163)

* Correctly lookup assets when using a relative build directory

* Hah, var ...

* Add e2e test for relative paths

* Format svg
@lock lock bot locked and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants