Skip to content

Commit 2abda8d

Browse files
committed
Fix tests not being compatible with Windows paths joining
1 parent 385a3e5 commit 2abda8d

File tree

24 files changed

+110
-109
lines changed

24 files changed

+110
-109
lines changed

docs/src/lib/dev/devdocs.data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const filesToInclude = files.filter(each => {
1414
return each.name !== 'index.md';
1515
}).map(each => {
1616
// Paths are resolved relative to the src directory
17-
return pathlib.join('/lib/dev', each.name);
17+
return pathlib.posix.join('/lib/dev', each.name);
1818
});
1919

2020
export default createContentLoader(filesToInclude, {

docs/src/modules/2-bundle/3-editing.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ This adds the dependency to `devDependencies` instead.
3838
> yarn add @sourceacademy/modules-lib@workspace:^
3939
> ```
4040
41+
### React Within bundles
42+
Currently, the way bundles are loaded by `js-slang` means that React cannot be externalized for bundles. `js-slang` simply has no way to provide React
43+
from the frontend to the bundle.
44+
45+
This means that tools like the React DevTools will not be able to work correctly during development with the frontend.
46+
47+
Refer to the [issue](https://github.com/source-academy/modules/issues/211) tracking this functionality.
48+
4149
## Bundle Conventions
4250
To ensure that bundles conform to the different Source language specifications, there are a few rules that bundles need to abide by.
4351
Refer to [this list](./4-conventions/index) for more information.

docs/src/modules/4-advanced/testing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ test('CurveTab', () => {
4343
})
4444
```
4545

46+
For more instructions on how to write tests you can refer to the [Vitest website](https://vitest.dev/guide/#writing-tests).
47+
4648
## Running Tests
4749
To run tests for a given bundle or tab, simply run either of the following commands within the directory:
4850
```sh

lib/buildtools/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const command = getBuildCommand({
3535
const newDirectory = pathlib.relative('./bin', repoRoot);
3636
return {
3737
external: true,
38-
path: pathlib.join(newDirectory, base),
38+
path: pathlib.posix.join(newDirectory, base),
3939
};
4040
});
4141
}

lib/buildtools/src/build/__tests__/all.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pathlib from 'path';
12
import { afterEach, describe, expect, test, vi } from 'vitest';
23
import { testMocksDir } from '../../__tests__/fixtures.js';
34
import * as docs from '../../build/docs/index.js';
@@ -33,7 +34,7 @@ describe('Test the buildAll command', () => {
3334
});
3435

3536
describe('Test command with a bundle', () => {
36-
const bundlePath = `${testMocksDir}/bundles/test0`;
37+
const bundlePath = pathlib.join(testMocksDir, 'bundles', 'test0');
3738

3839
test('Regular execution for a bundle', async () => {
3940
mockedBuildBundle.mockResolvedValueOnce({
@@ -163,7 +164,7 @@ describe('Test the buildAll command', () => {
163164
});
164165

165166
describe('Test command with a tab', () => {
166-
const tabPath = `${testMocksDir}/tabs/tab0`;
167+
const tabPath = pathlib.join(testMocksDir, 'tabs', 'tab0');
167168

168169
test('Regular execution for a tab', async () => {
169170
mockedBuildTab.mockResolvedValueOnce({

lib/buildtools/src/build/docs/__tests__/index.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ describe('Test buildSingleBundleDocs', () => {
5454
const result = await buildSingleBundleDocs(mockBundle, outDir, td.LogLevel.None);
5555
expectSuccess(result.severity);
5656

57-
expect(mockGenerateJson).toHaveBeenCalledExactlyOnceWith(project, `${bundlesDir}/test0/dist/docs.json`);
58-
expect(fs.mkdir).toHaveBeenCalledExactlyOnceWith(`${outDir}/jsons`, { recursive: true });
57+
expect(mockGenerateJson).toHaveBeenCalledExactlyOnceWith(project, pathlib.join(bundlesDir, 'test0', 'dist', 'docs.json'));
58+
expect(fs.mkdir).toHaveBeenCalledExactlyOnceWith(pathlib.join(outDir,'jsons'), { recursive: true });
5959
expect(json.buildJson).toHaveBeenCalledTimes(1);
6060
});
6161
});
@@ -68,7 +68,7 @@ describe('Test buildHtml', () => {
6868
test0: mockBundle,
6969
test1: {
7070
type: 'bundle',
71-
directory: `${bundlesDir}/test1`,
71+
directory: pathlib.join(bundlesDir, 'test1'),
7272
manifest: {},
7373
name: 'test1'
7474
}
@@ -94,8 +94,8 @@ describe('Test buildHtml', () => {
9494

9595
const result = await buildHtml(bundles, outDir, td.LogLevel.None);
9696
expectSuccess(result.severity);
97-
expect(result.path).toEqual(`${outDir}/documentation`);
98-
expect(generateDocs).toHaveBeenCalledExactlyOnceWith(project, `${outDir}/documentation`);
97+
expect(result.path).toEqual(pathlib.join(outDir, 'documentation'));
98+
expect(generateDocs).toHaveBeenCalledExactlyOnceWith(project, pathlib.join(outDir, 'documentation'));
9999
});
100100

101101
test('Generation of HTML when not all bundles have been generated', async () => {

lib/buildtools/src/build/docs/__tests__/json.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'fs/promises';
2+
import pathlib from 'path';
23
import { bundlesDir, outDir } from '@sourceacademy/modules-repotools/getGitRoot';
34
import type { ResolvedBundle } from '@sourceacademy/modules-repotools/types';
45
import * as td from 'typedoc';
@@ -39,7 +40,7 @@ describe('Test buildJson', () => {
3940

4041
expect(fs.writeFile).toHaveBeenCalledOnce();
4142
const { calls: [[path, data]] } = mockedWriteFile.mock;
42-
expect(path).toEqual(`${outDir}/jsons/test0.json`);
43+
expect(path).toEqual(pathlib.join(outDir, 'jsons', 'test0.json'));
4344
expect(data).toMatchInlineSnapshot(`
4445
"{
4546
"test_function": {
@@ -72,7 +73,7 @@ describe('Test buildJson', () => {
7273

7374
expect(fs.writeFile).toHaveBeenCalledOnce();
7475
const { calls: [[path, data]] } = mockedWriteFile.mock;
75-
expect(path).toEqual(`${outDir}/jsons/test0.json`);
76+
expect(path).toEqual(pathlib.join(outDir, 'jsons', 'test0.json'));
7677
expect(data).toMatchInlineSnapshot(`
7778
"{
7879
"test_function": {
@@ -106,7 +107,7 @@ describe('Test buildJson', () => {
106107

107108
expect(fs.writeFile).toHaveBeenCalledOnce();
108109
const { calls: [[path, data]] } = mockedWriteFile.mock;
109-
expect(path).toEqual(`${outDir}/jsons/test0.json`);
110+
expect(path).toEqual(pathlib.join(outDir, 'jsons', 'test0.json'));
110111
expect(data).toMatchInlineSnapshot(`
111112
"{
112113
"test_function": {

lib/buildtools/src/build/docs/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'fs/promises';
2+
import pathlib from 'path';
23
import type { BuildResult, ResolvedBundle, ResultType } from '@sourceacademy/modules-repotools/types';
34
import { mapAsync } from '@sourceacademy/modules-repotools/utils';
45
import * as td from 'typedoc';
@@ -22,7 +23,7 @@ export async function buildSingleBundleDocs(bundle: ResolvedBundle, outDir: stri
2223
};
2324
}
2425

25-
await app.generateJson(project, `${bundle.directory}/dist/docs.json`);
26+
await app.generateJson(project, pathlib.join(bundle.directory, 'dist', 'docs.json'));
2627

2728
if (app.logger.hasErrors()) {
2829
return {
@@ -33,7 +34,7 @@ export async function buildSingleBundleDocs(bundle: ResolvedBundle, outDir: stri
3334
};
3435
}
3536

36-
await fs.mkdir(`${outDir}/jsons`, { recursive: true });
37+
await fs.mkdir(pathlib.join(outDir, 'jsons'), { recursive: true });
3738
return buildJson(bundle, outDir, project);
3839
}
3940

@@ -45,7 +46,7 @@ type BuildHtmlResult = ResultType;
4546
export async function buildHtml(bundles: Record<string, ResolvedBundle>, outDir: string, logLevel: td.LogLevel): Promise<BuildHtmlResult> {
4647
const jsonStats = await mapAsync(Object.values(bundles), async ({ name, directory }) => {
4748
try {
48-
const stats = await fs.stat(`${directory}/dist/docs.json`);
49+
const stats = await fs.stat(pathlib.join(directory, 'dist', 'docs.json'));
4950
return stats.isFile() ? undefined : name;
5051
} catch {
5152
return name;
@@ -71,7 +72,7 @@ export async function buildHtml(bundles: Record<string, ResolvedBundle>, outDir:
7172
};
7273
}
7374

74-
await app.generateDocs(project, `${outDir}/documentation`);
75+
await app.generateDocs(project, pathlib.join(outDir, 'documentation'));
7576
if (app.logger.hasErrors()) {
7677
return {
7778
severity: 'error',

lib/buildtools/src/build/docs/json.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Code for building JSON documentation specifically
2-
32
import fs from 'fs/promises';
3+
import pathlib from 'path';
44
import type { BuildResult, ResolvedBundle } from '@sourceacademy/modules-repotools/types';
55
import * as td from 'typedoc';
66
import drawdown from './drawdown.js';
@@ -163,7 +163,7 @@ export async function buildJson(bundle: ResolvedBundle, outDir: string, reflecti
163163
};
164164
}
165165

166-
const outpath = `${outDir}/jsons/${bundle.name}.json`;
166+
const outpath = pathlib.join(outDir, 'jsons', `${bundle.name}.json`);
167167
await fs.writeFile(outpath, JSON.stringify(jsonData, null, 2));
168168

169169
if (warnings.length > 0) {

lib/buildtools/src/build/docs/typedoc.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pathlib from 'path';
12
import type { ResolvedBundle } from '@sourceacademy/modules-repotools/types';
23
import * as td from 'typedoc';
34

@@ -20,8 +21,8 @@ export function initTypedocForJson(bundle: ResolvedBundle, logLevel: td.LogLevel
2021
...typedocPackageOptions,
2122
name: bundle.name,
2223
logLevel,
23-
entryPoints: [`${bundle.directory}/src/index.ts`],
24-
tsconfig: `${bundle.directory}/tsconfig.json`,
24+
entryPoints: [pathlib.join(bundle.directory, 'src', 'index.ts')],
25+
tsconfig: pathlib.join(bundle.directory, 'tsconfig.json')
2526
});
2627
}
2728

@@ -34,8 +35,8 @@ export function initTypedocForHtml(bundles: Record<string, ResolvedBundle>, logL
3435
...typedocPackageOptions,
3536
name: 'Source Academy Modules',
3637
logLevel,
37-
entryPoints: Object.values(bundles).map(({ directory }) => `${directory}/dist/docs.json`),
38+
entryPoints: Object.values(bundles).map(({ directory }) => pathlib.join(directory, 'dist', 'docs.json')),
3839
entryPointStrategy: 'merge',
39-
readme: `${import.meta.dirname}/docsreadme.md`,
40+
readme: pathlib.join(import.meta.dirname, 'docsreadme.md'),
4041
});
4142
}

0 commit comments

Comments
 (0)