-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap tree passed to preprocessors with moduleName
- Loading branch information
Matthew Edwards
committed
May 19, 2022
1 parent
f843868
commit b370bfe
Showing
4 changed files
with
189 additions
and
26 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
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,133 @@ | ||
import { Project, BuildResult, expectFilesAt, ExpectFile } from '@embroider/test-support'; | ||
import { throwOnWarnings } from '@embroider/core'; | ||
import merge from 'lodash/merge'; | ||
|
||
describe('preprocessors tests', function () { | ||
jest.setTimeout(120000); | ||
let build: BuildResult; | ||
let app: Project; | ||
let expectFile: ExpectFile; | ||
|
||
throwOnWarnings(); | ||
|
||
beforeAll(async function () { | ||
app = Project.emberNew('my-app'); | ||
|
||
const PKG_NAME_ADDON_WITH_PREPROCESS = 'addon-with-preprocess'; | ||
|
||
merge(app.files, { | ||
config: { | ||
'targets.js': `module.exports = { browsers: ['last 1 Chrome versions'] }`, | ||
}, | ||
app: { | ||
components: { | ||
'from-the-app.js': ` | ||
import Component from '@glimmer/component'; | ||
export default class extends Component {} | ||
`, | ||
'from-the-app.hbs': `<div>{{this.title}}</div><Greeting/>`, | ||
}, | ||
}, | ||
}); | ||
|
||
let addonWithPreprocess = app.addAddon(PKG_NAME_ADDON_WITH_PREPROCESS); | ||
|
||
const INDEX_JS_WITH_PREPROCESSOR = `const { map } = require('broccoli-stew'); | ||
module.exports = { | ||
name: require('./package').name, | ||
setupPreprocessorRegistry(type, registry) { | ||
if (type !== 'parent') { | ||
return; | ||
} | ||
registry.add('js', { | ||
name: 'special-path-processor', | ||
toTree(tree, inputPath) { | ||
if (inputPath !== '/') { | ||
return tree; | ||
} | ||
let augmented = map( | ||
tree, | ||
'**/*.{js,css}', | ||
function (content, relativePath) { | ||
console.log('$$$$' + relativePath); | ||
return \`/*path@\${relativePath}*/\n\${content}\`; | ||
} | ||
); | ||
return augmented; | ||
}, | ||
}); | ||
} | ||
}; | ||
`; | ||
|
||
addonWithPreprocess.linkDevPackage('broccoli-stew'); | ||
addonWithPreprocess.files['index.js'] = INDEX_JS_WITH_PREPROCESSOR; | ||
|
||
let addon = app.addAddon('my-addon'); | ||
|
||
merge(addon.files, { | ||
app: { | ||
components: { | ||
'greeting.js': `export { default } from 'my-addon/components/greeting';`, | ||
}, | ||
}, | ||
addon: { | ||
components: { | ||
'greeting.js': ` | ||
import Component from '@glimmer/component'; | ||
export default class extends Component {} | ||
`, | ||
'greeting.hbs': `Hello World`, | ||
}, | ||
}, | ||
}); | ||
|
||
addon.pkg['ember-addon'] = { | ||
version: 1, | ||
type: 'addon', | ||
}; | ||
|
||
addon.addDependency(PKG_NAME_ADDON_WITH_PREPROCESS); | ||
|
||
build = await BuildResult.build(app, { | ||
stage: 2, | ||
type: 'app', | ||
emberAppOptions: { | ||
tests: false, | ||
}, | ||
}); | ||
expectFile = expectFilesAt(build.outputPath); | ||
}); | ||
|
||
afterAll(async () => { | ||
await build.cleanup(); | ||
}); | ||
|
||
test('dependencies are setup for this test suite correctly', () => { | ||
expectFile('package.json').exists(); | ||
expectFile('package.json').matches(/addon-with-preprocess/, 'has the preprocessor dependency'); | ||
expectFile('node_modules/my-addon/package.json').exists(); | ||
expectFile('node_modules/my-addon/package.json').matches( | ||
/addon-with-preprocess/, | ||
'has the preprocessor dependency' | ||
); | ||
expectFile('node_modules/addon-with-preprocess/package.json').exists(); | ||
}); | ||
|
||
test.skip('preprocessor has path for app code scoped with moduleName', () => { | ||
const assertFile = expectFile('components/from-the-app.js'); | ||
assertFile.exists(); | ||
// This is the expected output during an classic build. | ||
assertFile.matches(/path:my-app\/components\/from-the-app\.js/, 'has a path comment in app components'); | ||
}); | ||
|
||
test.only('preprocessor has path for addon code scoped with moduleName', () => { | ||
expectFile('node_modules/addon-with-preprocess/package.json').exists(); | ||
const assertFile = expectFile('node_modules/my-addon/components/greeting.js'); | ||
assertFile.matches(/\/\/path:my-addon\/components\/from-the-app\.js/, 'has a path comment in app components'); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -5650,14 +5650,14 @@ browserify-zlib@^0.2.0: | |
pako "~1.0.5" | ||
|
||
browserslist@^3.2.6, browserslist@^4.0.0, browserslist@^4.14.0, browserslist@^4.14.5, browserslist@^4.17.5, browserslist@^4.19.1: | ||
version "4.19.1" | ||
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.19.1.tgz#4ac0435b35ab655896c31d53018b6dd5e9e4c9a3" | ||
integrity sha512-u2tbbG5PdKRTUoctO3NBD8FQ5HdPh1ZXPHzp1rwaa5jTc+RV9/+RlWiAIKmjRPQF+xbGM9Kklj5bZQFa2s/38A== | ||
version "4.20.3" | ||
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.20.3.tgz#eb7572f49ec430e054f56d52ff0ebe9be915f8bf" | ||
integrity sha512-NBhymBQl1zM0Y5dQT/O+xiLP9/rzOIQdKM/eMJBAq7yBgaB6krIYLGejrwVYnSHZdqjscB1SPuAjHwxjvN6Wdg== | ||
dependencies: | ||
caniuse-lite "^1.0.30001286" | ||
electron-to-chromium "^1.4.17" | ||
caniuse-lite "^1.0.30001332" | ||
electron-to-chromium "^1.4.118" | ||
escalade "^3.1.1" | ||
node-releases "^2.0.1" | ||
node-releases "^2.0.3" | ||
picocolors "^1.0.0" | ||
|
||
[email protected]: | ||
|
@@ -5889,11 +5889,16 @@ caniuse-api@^3.0.0: | |
lodash.memoize "^4.1.2" | ||
lodash.uniq "^4.5.0" | ||
|
||
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001286: | ||
caniuse-lite@^1.0.0: | ||
version "1.0.30001309" | ||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001309.tgz#e0ee78b9bec0704f67304b00ff3c5c0c768a9f62" | ||
integrity sha512-Pl8vfigmBXXq+/yUz1jUwULeq9xhMJznzdc/xwl4WclDAuebcTHVefpz8lE/bMI+UN7TOkSSe7B7RnZd6+dzjA== | ||
|
||
caniuse-lite@^1.0.30001332: | ||
version "1.0.30001340" | ||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001340.tgz#029a2f8bfc025d4820fafbfaa6259fd7778340c7" | ||
integrity sha512-jUNz+a9blQTQVu4uFcn17uAD8IDizPzQkIKh3LCJfg9BkyIqExYYdyc/ZSlWUSKb8iYiXxKsxbv4zYSvkqjrxw== | ||
|
||
capture-exit@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4" | ||
|
@@ -7125,10 +7130,10 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" | ||
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= | ||
|
||
electron-to-chromium@^1.4.17: | ||
version "1.4.66" | ||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.66.tgz#d7453d363dcd7b06ed1757adcde34d724e27b367" | ||
integrity sha512-f1RXFMsvwufWLwYUxTiP7HmjprKXrqEWHiQkjAYa9DJeVIlZk5v8gBGcaV+FhtXLly6C1OTVzQY+2UQrACiLlg== | ||
electron-to-chromium@^1.4.118: | ||
version "1.4.137" | ||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.137.tgz#186180a45617283f1c012284458510cd99d6787f" | ||
integrity sha512-0Rcpald12O11BUogJagX3HsCN3FE83DSqWjgXoHo5a72KUKMSfI39XBgJpgNNxS9fuGzytaFjE06kZkiVFy2qA== | ||
|
||
elliptic@^6.5.3: | ||
version "6.5.4" | ||
|
@@ -13848,15 +13853,15 @@ node-notifier@^9.0.1: | |
uuid "^8.3.0" | ||
which "^2.0.2" | ||
|
||
node-releases@^2.0.1: | ||
version "2.0.2" | ||
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.2.tgz#7139fe71e2f4f11b47d4d2986aaf8c48699e0c01" | ||
integrity sha512-XxYDdcQ6eKqp/YjI+tb2C5WM2LgjnZrfYg4vgQt49EK268b6gYCHsBLrK2qvJo4FmCtqmKezb0WZFK4fkrZNsg== | ||
node-releases@^2.0.3: | ||
version "2.0.4" | ||
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.4.tgz#f38252370c43854dc48aa431c766c6c398f40476" | ||
integrity sha512-gbMzqQtTtDz/00jQzZ21PQzdI9PyLYqUSvD0p3naOhX4odFji0ZxYdnVwPTxmSwkmxhcFImpozceidSG+AgoPQ== | ||
|
||
[email protected].2: | ||
version "0.7.2" | ||
resolved "https://registry.yarnpkg.com/node-watch/-/node-watch-0.7.2.tgz#545f057da8500487eb8287adcb4cb5a7338d7e21" | ||
integrity sha512-g53VjSARRv1JdST0LZRIg8RiuLr1TaBbVPsVvxh0/0Ymvi0xYUjDuoqQQAWtHJQUXhiShowPT/aXKNeHBcyQsw== | ||
[email protected].3: | ||
version "0.7.3" | ||
resolved "https://registry.yarnpkg.com/node-watch/-/node-watch-0.7.3.tgz#6d4db88e39c8d09d3ea61d6568d80e5975abc7ab" | ||
integrity sha512-3l4E8uMPY1HdMMryPRUAl+oIHtXtyiTlIiESNSVSNxcPfzAFzeTbXFQkZfAwBbo0B1qMSG8nUABx+Gd+YrbKrQ== | ||
|
||
nopt@^3.0.6: | ||
version "3.0.6" | ||
|
@@ -14996,12 +15001,12 @@ qunit-dom@^1.6.0: | |
ember-cli-version-checker "^5.1.1" | ||
|
||
qunit@^2.14.1, qunit@^2.16.0: | ||
version "2.17.2" | ||
resolved "https://registry.yarnpkg.com/qunit/-/qunit-2.17.2.tgz#5cb278e131d931f25c109a0fdb0518be7754c25a" | ||
integrity sha512-17isVvuOmALzsPjiV7wFg/6O5vJYXBrQZPwocfQSSh0I/rXvfX7bKMFJ4GMVW3U4P8r2mBeUy8EAngti4QD2Vw== | ||
version "2.19.1" | ||
resolved "https://registry.yarnpkg.com/qunit/-/qunit-2.19.1.tgz#eb1afd188da9e47f07c13aa70461a1d9c4505490" | ||
integrity sha512-gSGuw0vErE/rNjnlBW/JmE7NNubBlGrDPQvsug32ejYhcVFuZec9yoU0+C30+UgeCGwq6Ap89K65dMGo+kDGZQ== | ||
dependencies: | ||
commander "7.2.0" | ||
node-watch "0.7.2" | ||
node-watch "0.7.3" | ||
tiny-glob "0.2.9" | ||
|
||
randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5, randombytes@^2.1.0: | ||
|