Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c19ac91
commit 23fa5c6
Showing
12 changed files
with
3,992 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
lib/ | ||
example/ | ||
test/output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,8 @@ extends: eslint-config-shakacode/base | |
globals: | ||
__DEBUG__: true | ||
|
||
env: | ||
jest: true | ||
|
||
ecmaFeatures: | ||
restParams: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ node_modules/ | |
*.log | ||
npm-debug.log* | ||
.DS_Store | ||
test/output | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`sass-resources-loader resources should include resources 1`] = ` | ||
"$text-color: $ccc; | ||
div { | ||
display: block; | ||
color: $text-color; | ||
}" | ||
`; | ||
|
||
exports[`sass-resources-loader resources should parse array resources 1`] = ` | ||
" | ||
div { | ||
display: block; | ||
color: $text-color; | ||
} | ||
" | ||
`; | ||
|
||
exports[`sass-resources-loader resources should parse resource 1`] = ` | ||
" | ||
div { | ||
display: block; | ||
color: $text-color; | ||
} | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
const path = require('path'); | ||
const webpack = require('webpack'); | ||
const merge = require('webpack-merge'); | ||
const pathToLoader = require.resolve('../lib/loader.js'); | ||
|
||
function runWebpack(baseConfig, done) { | ||
const webpackConfig = merge({ | ||
output: { | ||
path: path.join(__dirname, 'output'), | ||
libraryTarget: 'commonjs2', | ||
}, | ||
}, baseConfig); | ||
|
||
webpack(webpackConfig, (webpackErr, stats) => { | ||
const err = webpackErr || | ||
(stats.hasErrors() && stats.compilation.errors[0]) || | ||
(stats.hasWarnings() && stats.compilation.warnings[0]); | ||
|
||
done(err || null); | ||
}); | ||
} | ||
|
||
function execTest(testId, options) { | ||
return new Promise((resolve, reject) => { | ||
const baseConfig = merge({ | ||
entry: path.resolve(__dirname, 'scss', `${testId}.scss`), | ||
output: { | ||
filename: `${testId}.js`, | ||
}, | ||
module: { | ||
rules: [{ | ||
test: /\.scss$/, | ||
use: [ | ||
{ loader: 'raw-loader' }, | ||
{ | ||
loader: pathToLoader, | ||
options, | ||
}, | ||
], | ||
}], | ||
}, | ||
}); | ||
|
||
runWebpack(baseConfig, (err) => err ? reject(err) : resolve()); | ||
}); | ||
} | ||
|
||
describe(`sass-resources-loader`, () => { | ||
describe('resources', () => { | ||
it('should parse resource', () => execTest('empty', { | ||
resources: path.resolve(__dirname, './scss/*.scss'), | ||
}).then(() => { | ||
const output = require('./output/empty'); | ||
expect(output).toMatchSnapshot(); | ||
})); | ||
|
||
it('should parse array resources', () => execTest('empty2', { | ||
resources: [ | ||
path.resolve(__dirname, './scss/*.scss'), | ||
], | ||
}).then(() => { | ||
const output = require('./output/empty2'); | ||
expect(output).toMatchSnapshot(); | ||
})); | ||
|
||
it('should include resources', () => execTest('imports', { | ||
resources: [ | ||
path.resolve(__dirname, './scss/variables/*.scss'), | ||
], | ||
}).then(() => { | ||
const output = require('./output/imports'); | ||
expect(output).toMatchSnapshot(); | ||
})); | ||
|
||
it('should throw error when no resources provided', (done) => { | ||
runWebpack({ | ||
entry: path.resolve(__dirname, 'scss', 'empty.scss'), | ||
module: { | ||
rules: [{ | ||
test: /\.scss$/, | ||
use: [ | ||
{ loader: 'raw-loader' }, | ||
{ | ||
loader: pathToLoader, | ||
}, | ||
], | ||
}], | ||
}, | ||
}, (err) => { | ||
expect(err.message).toMatch(/Can\'t find sass resources in your config/); | ||
expect(err.message).toMatch(/Make sure loader.options.resources exists/); | ||
done(); | ||
}); | ||
}); | ||
it('should throw error when resources are empty', (done) => { | ||
runWebpack({ | ||
entry: path.resolve(__dirname, 'scss', 'empty.scss'), | ||
module: { | ||
rules: [{ | ||
test: /\.scss$/, | ||
use: [ | ||
{ loader: 'raw-loader' }, | ||
{ | ||
loader: pathToLoader, | ||
options: { | ||
resources: [], | ||
}, | ||
}, | ||
], | ||
}], | ||
}, | ||
}, (err) => { | ||
expect(err.message).toMatch(/Something wrong with provided resources/); | ||
expect(err.message).toMatch(/Make sure \'options.resources\' is String or Array of Strings/); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('imports', () => { | ||
it('should not rewrite path for imports with ~', () => { | ||
const getNewImportPath = require('../lib/utils/rewriteImports').getNewImportPath; | ||
expect(getNewImportPath('~/bootstrap', '', '')).toMatch('~/bootstrap'); | ||
}); | ||
}); | ||
}); |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
div { | ||
display: block; | ||
color: $text-color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$text-color: $ccc; |
Oops, something went wrong.