test(docs-infra): fix `create-example` tests on Windows (#41842)
Previously, the tests in `create-example.spec.ts` made assertions using some hard-coded absolute paths (something like `/foo/bar`). This caused the tests to fail on Windows, where the absolute paths are prefixed with the drive letter (something like `C:/foo/bar`). This commit uses `path.resolve()` to ensure paths are converted to the format used on the current OS. PR Close #41842
This commit is contained in:
parent
d580b27195
commit
36e10e7932
|
@ -24,10 +24,11 @@ describe('create-example tool', () => {
|
||||||
createEmptyExample('foo-bar', '/path/to/foo-bar');
|
createEmptyExample('foo-bar', '/path/to/foo-bar');
|
||||||
expect(writeFileSpy).toHaveBeenCalledTimes(2);
|
expect(writeFileSpy).toHaveBeenCalledTimes(2);
|
||||||
expect(writeFileSpy)
|
expect(writeFileSpy)
|
||||||
.toHaveBeenCalledWith(`/path/to/foo-bar/${EXAMPLE_CONFIG_FILENAME}`, jasmine.any(String));
|
.toHaveBeenCalledWith(
|
||||||
|
path.resolve(`/path/to/foo-bar/${EXAMPLE_CONFIG_FILENAME}`), jasmine.any(String));
|
||||||
expect(writeFileSpy)
|
expect(writeFileSpy)
|
||||||
.toHaveBeenCalledWith(
|
.toHaveBeenCalledWith(
|
||||||
`/path/to/foo-bar/${STACKBLITZ_CONFIG_FILENAME}`, jasmine.any(String));
|
path.resolve(`/path/to/foo-bar/${STACKBLITZ_CONFIG_FILENAME}`), jasmine.any(String));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ describe('create-example tool', () => {
|
||||||
it('should write a JSON file to disk', () => {
|
it('should write a JSON file to disk', () => {
|
||||||
const spy = spyOn(fs, 'writeFileSync');
|
const spy = spyOn(fs, 'writeFileSync');
|
||||||
writeExampleConfigFile('/foo/bar');
|
writeExampleConfigFile('/foo/bar');
|
||||||
expect(spy).toHaveBeenCalledWith(`/foo/bar/${EXAMPLE_CONFIG_FILENAME}`, '');
|
expect(spy).toHaveBeenCalledWith(path.resolve(`/foo/bar/${EXAMPLE_CONFIG_FILENAME}`), '');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ describe('create-example tool', () => {
|
||||||
it('should write a JSON file to disk', () => {
|
it('should write a JSON file to disk', () => {
|
||||||
const spy = spyOn(fs, 'writeFileSync');
|
const spy = spyOn(fs, 'writeFileSync');
|
||||||
writeStackBlitzFile('bar-bar', '/foo/bar-bar');
|
writeStackBlitzFile('bar-bar', '/foo/bar-bar');
|
||||||
expect(spy).toHaveBeenCalledWith(`/foo/bar-bar/${STACKBLITZ_CONFIG_FILENAME}`, [
|
expect(spy).toHaveBeenCalledWith(path.resolve(`/foo/bar-bar/${STACKBLITZ_CONFIG_FILENAME}`), [
|
||||||
'{',
|
'{',
|
||||||
' "description": "Bar Bar",',
|
' "description": "Bar Bar",',
|
||||||
' "files": [',
|
' "files": [',
|
||||||
|
@ -108,13 +109,13 @@ describe('create-example tool', () => {
|
||||||
expect(readFileSyncSpy).toHaveBeenCalledWith(sourceGitIgnorePath, 'utf8');
|
expect(readFileSyncSpy).toHaveBeenCalledWith(sourceGitIgnorePath, 'utf8');
|
||||||
|
|
||||||
expect(ensureDirSyncSpy.calls.allArgs()).toEqual([
|
expect(ensureDirSyncSpy.calls.allArgs()).toEqual([
|
||||||
['/path/to/test-example/a'],
|
[path.resolve('/path/to/test-example/a')],
|
||||||
['/path/to/test-example'],
|
[path.resolve('/path/to/test-example')],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(copySyncSpy.calls.allArgs()).toEqual([
|
expect(copySyncSpy.calls.allArgs()).toEqual([
|
||||||
['/source/path/a/c', '/path/to/test-example/a/c'],
|
[path.resolve('/source/path/a/c'), path.resolve('/path/to/test-example/a/c')],
|
||||||
['/source/path/x.ts', '/path/to/test-example/x.ts'],
|
[path.resolve('/source/path/x.ts'), path.resolve('/path/to/test-example/x.ts')],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue