Skip to content

Commit

Permalink
concretize tests to ensure our assertions aren't platform dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
alicewriteswrongs committed Jul 5, 2023
1 parent 6aaf420 commit 662eca3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const generateCustomElementsTypesOutput = async (
const isBundleExport = outputTarget.customElementsExportBehavior === 'bundle';

// the path where we're going to write the typedef for the whole dist-custom-elements output
const customElementsDtsPath = join(outputTarget.dir!, 'index.d.ts');
const customElementsDtsPath = normalizePath(join(outputTarget.dir!, 'index.d.ts'));
// the directory where types for the individual components are written
const componentsTypeDirectoryRelPath = relative(outputTarget.dir!, typesDir);

Expand Down
41 changes: 11 additions & 30 deletions src/compiler/output-targets/test/custom-elements-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from '@stencil/core/testing';
import { DIST_CUSTOM_ELEMENTS, normalizePath } from '@utils';
import path from 'path';
import { join, relative } from 'path';

import type * as d from '../../../declarations';
import { stubComponentCompilerMeta } from '../../types/tests/ComponentCompilerMeta.stub';
Expand Down Expand Up @@ -62,17 +61,11 @@ describe('Custom Elements Typedef generation', () => {

await generateCustomElementsTypes(config, compilerCtx, buildCtx, 'types_dir');

const componentsTypeDirectoryPath = normalizePath(relative('my-best-dir', join('types_dir', 'components')));

const expectedTypedefOutput = [
'/* TestApp custom elements */',
`export { StubCmp as MyComponent } from '${normalizePath(
join(componentsTypeDirectoryPath, 'my-component', 'my-component')
)}';`,
`export { StubCmp as MyComponent } from '../types_dir/components/my-component/my-component';`,
`export { defineCustomElement as defineCustomElementMyComponent } from './my-component';`,
`export { MyBestComponent as MyBestComponent } from '${normalizePath(
join(componentsTypeDirectoryPath, 'the-other-component', 'my-real-best-component')
)}';`,
`export { MyBestComponent as MyBestComponent } from '../types_dir/components/the-other-component/my-real-best-component';`,
`export { defineCustomElement as defineCustomElementMyBestComponent } from './my-best-component';`,
'',
'/**',
Expand Down Expand Up @@ -106,13 +99,9 @@ describe('Custom Elements Typedef generation', () => {
'',
].join('\n');

expect(compilerCtx.fs.writeFile).toHaveBeenCalledWith(
normalizePath(join('my-best-dir', 'index.d.ts')),
expectedTypedefOutput,
{
outputTargetType: DIST_CUSTOM_ELEMENTS,
}
);
expect(compilerCtx.fs.writeFile).toHaveBeenCalledWith('./my-best-dir/index.d.ts', expectedTypedefOutput, {
outputTargetType: DIST_CUSTOM_ELEMENTS,
});

writeFileSpy.mockRestore();
});
Expand Down Expand Up @@ -169,13 +158,9 @@ describe('Custom Elements Typedef generation', () => {
'',
].join('\n');

expect(compilerCtx.fs.writeFile).toHaveBeenCalledWith(
normalizePath(join('my-best-dir', 'index.d.ts')),
expectedTypedefOutput,
{
outputTargetType: DIST_CUSTOM_ELEMENTS,
}
);
expect(compilerCtx.fs.writeFile).toHaveBeenCalledWith('./my-best-dir/index.d.ts', expectedTypedefOutput, {
outputTargetType: DIST_CUSTOM_ELEMENTS,
});

writeFileSpy.mockRestore();
});
Expand Down Expand Up @@ -241,13 +226,9 @@ describe('Custom Elements Typedef generation', () => {
'',
].join('\n');

expect(compilerCtx.fs.writeFile).toHaveBeenCalledWith(
normalizePath(join('my-best-dir', 'index.d.ts')),
expectedTypedefOutput,
{
outputTargetType: DIST_CUSTOM_ELEMENTS,
}
);
expect(compilerCtx.fs.writeFile).toHaveBeenCalledWith('./my-best-dir/index.d.ts', expectedTypedefOutput, {
outputTargetType: DIST_CUSTOM_ELEMENTS,
});

writeFileSpy.mockRestore();
});
Expand Down

0 comments on commit 662eca3

Please sign in to comment.