Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion testsuite/tests/util/Context-node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('context object', () => {

test('context', () => {
if (OS === 'Windows') {
expect(context.path('C:\\test.js')).toBe('C:/test.js');
expect(context.path('C:\\test.js')).toBe('file://C:/test.js');
} else {
expect(context.path('C:\\test.js')).toBe('C:\\test.js');
}
Expand Down
7 changes: 4 additions & 3 deletions testsuite/tests/util/Context-windows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ describe('context object', () => {

test('context', async () => {
let {context, hasWindow} = await import("#js/util/context.js");
expect(context.path('C:\\test.js')).toBe('C:/test.js');
expect(context.path('/C:/test.js')).toBe('C:/test.js');
expect(context.path('/test.js')).toBe('/test.js');
expect(context.path('C:\\test.js')).toBe('file://C:/test.js');
expect(context.path('/C:/test.js')).toBe('file://C:/test.js');
expect(context.path('/test.js')).toBe('file:///test.js');
expect(context.path('./test.js')).toBe('./test.js');
delete context.path;
expect(context).toEqual({window: window, document: window.document, os: 'Windows'});
expect(hasWindow).toBe(true);
Expand Down
7 changes: 6 additions & 1 deletion ts/util/asyncLoad/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import { context } from '../context.js';
declare const System: { import: (name: string, url?: string) => any };
declare const __dirname: string;

let root = 'file://' + context.path(__dirname).replace(/\/[^/]*\/[^/]*$/, '/');
let root =
'file://' +
context
.path(__dirname)
.replace(/\/[^/]*\/[^/]*$/, '/')
.replace(/^file:\/\//, '');

if (!mathjax.asyncLoad && typeof System !== 'undefined' && System.import) {
mathjax.asyncLoad = (name: string) => {
Expand Down
4 changes: 2 additions & 2 deletions ts/util/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ export const context = {
if (context.os === 'Windows') {
context.path = (file: string) =>
file.match(/^[/\\]?[a-zA-Z]:[/\\]/)
? file.replace(/\\/g, '/').replace(/^\//, '')
: file;
? 'file://' + file.replace(/\\/g, '/').replace(/^\//, '')
: file.replace(/^\//, 'file:///');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now leads to an error in Context-node.test.ts:

Received: "file:///C:/test.js"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I forgot about this test (I didn't run it on windows, and that test is only performed there).

I fixed the test. I had to merge your fix/windows-tests branch to get the tests to run on windows, but that is still listed as a draft PR. Do you want to make it a full PR so we can include it in 4.1.1?

}