Skip to content

Commit

Permalink
🐛 fix updateURL resolution
Browse files Browse the repository at this point in the history
Fix #82
  • Loading branch information
momocow committed Mar 9, 2023
1 parent aa441fd commit 4f9f9cc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
9 changes: 4 additions & 5 deletions lib/features/resolve-base-urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ export class ResolveBaseURLs extends Feature<ResolveBaseURLsOptions> {
if (headers.updateURL === undefined) {
headers = {
...headers,
updateURL: metajs
? new URL(metajsFile, updateBaseURL).toString()
: updateBaseURL !== undefined
? new URL(userjsFile, updateBaseURL).toString()
: headers.downloadURL,
updateURL: new URL(
metajs ? metajsFile : userjsFile,
updateBaseURL ?? downloadBaseURL,
).toString(),
};
}

Expand Down
9 changes: 6 additions & 3 deletions test/integration/resolve-base-urls/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { GlobalFixtures } from '../fixtures';

export class Fixtures extends GlobalFixtures {
public static readonly downloadURL =
public static readonly downloadURLWithUserjs =
'http://download.example.com/output.user.js';

public static readonly updateURLByMetajs =
public static readonly downloadURLWithMetajs =
'http://download.example.com/output.meta.js';

public static readonly updateURLWithMetajs =
'http://update.example.com/output.meta.js';

public static readonly updateURLByUserjs =
public static readonly updateURLWithUserjs =
'http://update.example.com/output.user.js';
}
37 changes: 31 additions & 6 deletions test/integration/resolve-base-urls/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('resolve base urls', () => {
const findDownloadURL = findTags.bind(
undefined,
'downloadURL',
Fixtures.downloadURL,
Fixtures.downloadURLWithUserjs,
);

beforeEach(async () => {
Expand All @@ -26,7 +26,7 @@ describe('resolve base urls', () => {
const findUpdateURLByMetajs = findTags.bind(
undefined,
'updateURL',
Fixtures.updateURLByMetajs,
Fixtures.updateURLWithMetajs,
);

const output = await compile(input, {
Expand All @@ -53,11 +53,11 @@ describe('resolve base urls', () => {
expect(findUpdateURLByMetajs(metaJs)).toHaveLength(1);
});

it('should resolve updateURL by userjs', async () => {
it('should resolve updateURL with updateBaseURL and userjs', async () => {
const findUpdateURLByUserjs = findTags.bind(
undefined,
'updateURL',
Fixtures.updateURLByUserjs,
Fixtures.updateURLWithUserjs,
);

const output = await compile(input, {
Expand All @@ -79,11 +79,11 @@ describe('resolve base urls', () => {
expect(findUpdateURLByUserjs(userJs)).toHaveLength(1);
});

it('should resolve updateURL by downloadURL', async () => {
it('should resolve updateURL by downloadBaseURL and userjs', async () => {
const findUpdateURLByDownloadURL = findTags.bind(
undefined,
'updateURL',
Fixtures.downloadURL,
Fixtures.downloadURLWithUserjs,
);

const output = await compile(input, {
Expand All @@ -103,4 +103,29 @@ describe('resolve base urls', () => {
expect(findDownloadURL(userJs)).toHaveLength(1);
expect(findUpdateURLByDownloadURL(userJs)).toHaveLength(1);
});

it('should resolve updateURL by downloadBaseURL and metajs', async () => {
const findUpdateURLByDownloadURL = findTags.bind(
undefined,
'updateURL',
Fixtures.downloadURLWithMetajs,
);

const output = await compile(input, {
...Fixtures.webpackConfig,
plugins: [
new UserscriptPlugin({
downloadBaseURL: new URL('http://download.example.com'),
metajs: true,
}),
],
});

const userJs = output
.readFileSync('/dist/output.user.js')
.toString('utf-8');

expect(findDownloadURL(userJs)).toHaveLength(1);
expect(findUpdateURLByDownloadURL(userJs)).toHaveLength(1);
});
});

0 comments on commit 4f9f9cc

Please sign in to comment.