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:
George Kalpakas 2021-04-27 22:50:11 +03:00 committed by Jessica Janiuk
parent d580b27195
commit 36e10e7932
1 changed files with 9 additions and 8 deletions

View File

@ -24,10 +24,11 @@ describe('create-example tool', () => {
createEmptyExample('foo-bar', '/path/to/foo-bar');
expect(writeFileSpy).toHaveBeenCalledTimes(2);
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)
.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', () => {
const spy = spyOn(fs, 'writeFileSync');
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', () => {
const spy = spyOn(fs, 'writeFileSync');
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",',
' "files": [',
@ -108,13 +109,13 @@ describe('create-example tool', () => {
expect(readFileSyncSpy).toHaveBeenCalledWith(sourceGitIgnorePath, 'utf8');
expect(ensureDirSyncSpy.calls.allArgs()).toEqual([
['/path/to/test-example/a'],
['/path/to/test-example'],
[path.resolve('/path/to/test-example/a')],
[path.resolve('/path/to/test-example')],
]);
expect(copySyncSpy.calls.allArgs()).toEqual([
['/source/path/a/c', '/path/to/test-example/a/c'],
['/source/path/x.ts', '/path/to/test-example/x.ts'],
[path.resolve('/source/path/a/c'), path.resolve('/path/to/test-example/a/c')],
[path.resolve('/source/path/x.ts'), path.resolve('/path/to/test-example/x.ts')],
]);
});
});