-
Notifications
You must be signed in to change notification settings - Fork 142
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