guybedford / require-css

A RequireJS CSS loader plugin to allow CSS requires and optimization
MIT License
983 stars 364 forks source link

Recreated PR: Changed url pattern in normalize.js. Tests passed. #228

Closed alundiak closed 7 years ago

alundiak commented 7 years ago

I recreated PR, with changes from https://github.com/guybedford/require-css/pull/97 PR.

Decided to choose @dataway variant, but I agree with @fearphage there is for sure simplified version. And we will work it later.

Here is screenshot of RegExr.com, how pattern works:

screen shot 2017-02-19 at 17 45 40

During this PR, I added 2 new test cases:

assert(
    '@import statements with url()',
    normalize('@import url("test.css")', '/first/', '/second/'),
    '@import url("../first/test.css")'
);
// so that to test combination of @import and url()

assert(
    'multiple url includes on the same line (mixed)',
    normalize('src: url("../fonts/font.eot") format("embedded-opentype"), url("http://server.com/opensans.woff") format("woff");', '/base/', '/'),
    'src: url("fonts/font.eot") format("embedded-opentype"), url("http://server.com/opensans.woff") format("woff");'
);
// so that to test combination of absolute and protocol-based urls.

Her is test results:

--- Starting Require CSS Tests ---

Testing URL Base Conversions
  Changing subfolder... passed.
  Changing subfolder with backtrack... passed.
  Changing two subfolders with a folder... passed.
  Double forward slashes in relative URI... passed.
  protocol base urls work... passed.
  absolute protocol paths work with base conversion... passed.
  Converting with backtrack in fromBase... passed.

Testing Stylesheet Regular Expressions
  @import statements... passed.
  @import statements with url()... passed.
  url includes... passed.
  absolute url detection... passed.
  absolute url convert base... passed.
  absolute url convert base (http)... passed.
  multiple url includes on the same line... passed.
  multiple url includes on the same line (mixed)... passed.
  absolute URI test... passed.

--- Require CSS Tests Complete: 16 passed, 0 failed. ---

In scope of this PR, I also added requirejs to devDependencies, because it's needed by command node test/test.js aliased as npm test (from previous commits). Yes, I know, there is require-css/test/maxStylesTest/lib/require.js and I know it's the same version 2.1.10. And I did it on purpose. So far, I can't dramatically change lot of things I see in require-css module, but I will do it step-by-step.