Skip to content

Commit 0bf19ec

Browse files
barbados-clemensFrozenPandaz
authored andcommitted
fix(testing): handle path offsets for angular component testing (#12863)
(cherry picked from commit 5a137d0)
1 parent eae4b27 commit 0bf19ec

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

e2e/angular-extensions/src/cypress-component-tests.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ export class BtnStandaloneComponent {
7070
`
7171
);
7272
const btnModuleName = names(usedInAppLibName).className;
73+
updateFile(
74+
`apps/${appName}/src/app/app.component.scss`,
75+
`
76+
@use 'styleguide' as *;
7377
78+
h1 {
79+
@include headline;
80+
}`
81+
);
7482
updateFile(
7583
`apps/${appName}/src/app/app.module.ts`,
7684
`
@@ -135,7 +143,21 @@ import {CommonModule} from '@angular/common';
135143

136144
// make sure assets from the workspace root work.
137145
createFile('libs/assets/data.json', JSON.stringify({ data: 'data' }));
146+
createFile(
147+
'assets/styles/styleguide.scss',
148+
`
149+
@mixin headline {
150+
font-weight: bold;
151+
color: darkkhaki;
152+
background: lightcoral;
153+
font-weight: 24px;
154+
}
155+
`
156+
);
138157
updateProjectConfig(appName, (config) => {
158+
config.targets['build'].options.stylePreprocessorOptions = {
159+
includePaths: ['assets/styles'],
160+
};
139161
config.targets['build'].options.assets.push({
140162
glob: '**/*',
141163
input: 'libs/assets',

packages/angular/plugins/component-testing.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,21 @@ function normalizeBuildTargetOptions(
211211
? joinPathFragments(offset, script)
212212
: { ...script, input: joinPathFragments(offset, script.input) };
213213
});
214+
if (buildOptions.stylePreprocessorOptions?.includePaths.length > 0) {
215+
buildOptions.stylePreprocessorOptions = {
216+
includePaths: buildOptions.stylePreprocessorOptions.includePaths.map(
217+
(path) => {
218+
return joinPathFragments(offset, path);
219+
}
220+
),
221+
};
222+
}
214223
} else {
215224
const stylePath = getTempStylesForTailwind(ctContext);
216225
buildOptions.styles = stylePath ? [stylePath] : [];
217226
buildOptions.assets = [];
218227
buildOptions.scripts = [];
228+
buildOptions.stylePreprocessorOptions = { includePaths: [] };
219229
}
220230
const { root, sourceRoot } =
221231
buildContext.projectGraph.nodes[buildContext.projectName].data;

0 commit comments

Comments
 (0)