Skip to content

Commit ff17622

Browse files
committed
fixup! feat(material/core): move mdc-helpers to material/core
1 parent 2520bf3 commit ff17622

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

src/material/core/theming/tests/theming-api.spec.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as path from 'path';
55

66
import {compareNodes} from '../../../../../tools/postcss/compare-nodes';
77
import {createLocalAngularPackageImporter} from '../../../../../tools/sass/local-sass-importer';
8+
import {pathToFileURL} from 'url';
89

910
// Note: For Windows compatibility, we need to resolve the directory paths through runfiles
1011
// which are guaranteed to reside in the source tree.
@@ -13,6 +14,15 @@ const packagesDir = path.join(runfiles.resolveWorkspaceRelative('src/cdk/_index.
1314

1415
const localPackageSassImporter = createLocalAngularPackageImporter(packagesDir);
1516

17+
const mdcSassImporter = {
18+
findFileUrl: (url: string) => {
19+
if (url.toString().startsWith('@material')) {
20+
return pathToFileURL(path.join(runfiles.resolveWorkspaceRelative('./node_modules'), url));
21+
}
22+
return null;
23+
},
24+
};
25+
1626
describe('theming api', () => {
1727
/** Map of known selectors for density styles and their corresponding AST rule. */
1828
let knownDensitySelectors: Map<string, Rule>;
@@ -51,8 +61,6 @@ describe('theming api', () => {
5161
});
5262

5363
it('should not warn if color styles and density are not duplicated', () => {
54-
spyOn(process.stderr, 'write').and.callThrough();
55-
5664
const parsed = parse(
5765
transpile(`
5866
$theme: mat-light-theme((
@@ -78,7 +86,7 @@ describe('theming api', () => {
7886

7987
expect(hasDensityStyles(parsed, null)).toBe('all');
8088
expect(hasDensityStyles(parsed, '.dark-theme')).toBe('none');
81-
expect(process.stderr.write).toHaveBeenCalledTimes(0);
89+
expectNoWarning(/The same color styles are generated multiple times/);
8290
});
8391

8492
it('should warn if default density styles are duplicated', () => {
@@ -217,7 +225,6 @@ describe('theming api', () => {
217225
});
218226

219227
it('not warn if default density would be generated multiple times', () => {
220-
spyOn(process.stderr, 'write');
221228
transpile(`
222229
$light-theme: mat-light-theme($mat-red, $mat-blue);
223230
$dark-theme: mat-dark-theme($mat-red, $mat-blue);
@@ -228,7 +235,7 @@ describe('theming api', () => {
228235
}
229236
`);
230237

231-
expect(process.stderr.write).toHaveBeenCalledTimes(0);
238+
expectNoWarning(/The same density styles are generated multiple times/);
232239
});
233240

234241
it('should be possible to modify color configuration directly', () => {
@@ -319,25 +326,36 @@ describe('theming api', () => {
319326
`,
320327
{
321328
loadPaths: [testDir],
322-
importers: [localPackageSassImporter],
329+
importers: [localPackageSassImporter, mdcSassImporter],
323330
},
324331
).css.toString();
325332
}
326333

334+
/** Expects the given warning to be reported in Sass. */
335+
function expectWarning(message: RegExp) {
336+
expect(getMatchingWarning(message))
337+
.withContext('Expected warning to be printed.')
338+
.toBeDefined();
339+
}
340+
341+
/** Expects the given warning not to be reported in Sass. */
342+
function expectNoWarning(message: RegExp) {
343+
expect(getMatchingWarning(message))
344+
.withContext('Expected no warning to be printed.')
345+
.toBeUndefined();
346+
}
347+
327348
/**
328-
* Expects the given warning to be reported in Sass. Dart sass directly writes
349+
* Gets first instance of the given warning reported in Sass. Dart sass directly writes
329350
* to the `process.stderr` stream, so we spy on the `stderr.write` method. We
330351
* cannot expect a specific amount of writes as Sass calls `stderr.write` multiple
331352
* times for a warning (e.g. spacing and stack trace)
332353
*/
333-
function expectWarning(message: RegExp) {
354+
function getMatchingWarning(message: RegExp) {
334355
const writeSpy = process.stderr.write as jasmine.Spy;
335-
const match = writeSpy.calls
336-
.all()
337-
.find(
338-
(s: jasmine.CallInfo<typeof process.stderr.write>) =>
339-
typeof s.args[0] === 'string' && message.test(s.args[0]),
340-
);
341-
expect(match).withContext('Expected warning to be printed.').toBeDefined();
356+
return (writeSpy.calls?.all() ?? []).find(
357+
(s: jasmine.CallInfo<typeof process.stderr.write>) =>
358+
typeof s.args[0] === 'string' && message.test(s.args[0]),
359+
);
342360
}
343361
});

0 commit comments

Comments
 (0)