fix(testing): handle path offsets for angular component testing (#12863)

This commit is contained in:
Caleb Ukle 2022-11-04 11:43:21 -05:00 committed by GitHub
parent 305f69477d
commit 5a137d0b3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -70,7 +70,15 @@ export class BtnStandaloneComponent {
` `
); );
const btnModuleName = names(usedInAppLibName).className; const btnModuleName = names(usedInAppLibName).className;
updateFile(
`apps/${appName}/src/app/app.component.scss`,
`
@use 'styleguide' as *;
h1 {
@include headline;
}`
);
updateFile( updateFile(
`apps/${appName}/src/app/app.module.ts`, `apps/${appName}/src/app/app.module.ts`,
` `
@ -135,7 +143,21 @@ import {CommonModule} from '@angular/common';
// make sure assets from the workspace root work. // make sure assets from the workspace root work.
createFile('libs/assets/data.json', JSON.stringify({ data: 'data' })); createFile('libs/assets/data.json', JSON.stringify({ data: 'data' }));
createFile(
'assets/styles/styleguide.scss',
`
@mixin headline {
font-weight: bold;
color: darkkhaki;
background: lightcoral;
font-weight: 24px;
}
`
);
updateProjectConfig(appName, (config) => { updateProjectConfig(appName, (config) => {
config.targets['build'].options.stylePreprocessorOptions = {
includePaths: ['assets/styles'],
};
config.targets['build'].options.assets.push({ config.targets['build'].options.assets.push({
glob: '**/*', glob: '**/*',
input: 'libs/assets', input: 'libs/assets',

View File

@ -211,11 +211,21 @@ function normalizeBuildTargetOptions(
? joinPathFragments(offset, script) ? joinPathFragments(offset, script)
: { ...script, input: joinPathFragments(offset, script.input) }; : { ...script, input: joinPathFragments(offset, script.input) };
}); });
if (buildOptions.stylePreprocessorOptions?.includePaths.length > 0) {
buildOptions.stylePreprocessorOptions = {
includePaths: buildOptions.stylePreprocessorOptions.includePaths.map(
(path) => {
return joinPathFragments(offset, path);
}
),
};
}
} else { } else {
const stylePath = getTempStylesForTailwind(ctContext); const stylePath = getTempStylesForTailwind(ctContext);
buildOptions.styles = stylePath ? [stylePath] : []; buildOptions.styles = stylePath ? [stylePath] : [];
buildOptions.assets = []; buildOptions.assets = [];
buildOptions.scripts = []; buildOptions.scripts = [];
buildOptions.stylePreprocessorOptions = { includePaths: [] };
} }
const { root, sourceRoot } = const { root, sourceRoot } =
buildContext.projectGraph.nodes[buildContext.projectName].data; buildContext.projectGraph.nodes[buildContext.projectName].data;