|
1 | 1 | import chai from 'chai'; |
2 | 2 | import { AdjustAssetUrls } from '@rocket/engine'; |
| 3 | +import { expectThrowsAsync } from './test-helpers.js'; |
3 | 4 |
|
4 | 5 | const { expect } = chai; |
5 | 6 |
|
@@ -48,7 +49,7 @@ describe('AdjustAssetUrls', () => { |
48 | 49 | ); |
49 | 50 | }); |
50 | 51 |
|
51 | | - it('ignores <a href="#foo"></a>', async () => { |
| 52 | + it('does not adjust <a href="#foo"></a>', async () => { |
52 | 53 | const adjust = new AdjustAssetUrls(); |
53 | 54 | expect(await adjust.transform('<a href="#foo">go</a>', options)).to.equal( |
54 | 55 | '<a href="#foo">go</a>', |
@@ -104,4 +105,43 @@ describe('AdjustAssetUrls', () => { |
104 | 105 | }), |
105 | 106 | ).to.equal('<a href="/">go</a>'); |
106 | 107 | }); |
| 108 | + |
| 109 | + it('adjust <a href="./about.rocket.js#some-id"></a>', async () => { |
| 110 | + const adjust = new AdjustAssetUrls(); |
| 111 | + expect(await adjust.transform('<a href="./about.rocket.js#some-id">go</a>', options)).to.equal( |
| 112 | + '<a href="/about/#some-id">go</a>', |
| 113 | + ); |
| 114 | + expect( |
| 115 | + await adjust.transform('<a href="./about.rocket.js#some-id">go</a>', { |
| 116 | + sourceRelativeFilePath: 'components/index.rocket.js', |
| 117 | + outputFilePath: '/my/path/to/__output/components/index.html', |
| 118 | + }), |
| 119 | + ).to.equal('<a href="/components/about/#some-id">go</a>'); |
| 120 | + |
| 121 | + expect( |
| 122 | + await adjust.transform('<a href="./about.rocket.js#some-id">go</a>', { |
| 123 | + sourceRelativeFilePath: 'components.rocket.js', |
| 124 | + outputFilePath: '/my/path/to/__output/components/index.html', |
| 125 | + }), |
| 126 | + ).to.equal('<a href="/about/#some-id">go</a>'); |
| 127 | + |
| 128 | + expect( |
| 129 | + await adjust.transform('<a href="./index.rocket.js#some-id">go</a>', { |
| 130 | + sourceRelativeFilePath: 'about.rocket.js', |
| 131 | + outputFilePath: '/my/path/to/__output/about/index.html', |
| 132 | + }), |
| 133 | + ).to.equal('<a href="/#some-id">go</a>'); |
| 134 | + }); |
| 135 | + |
| 136 | + it('still resolves private imports <img src="resolve:#src/logo.svg" />', async () => { |
| 137 | + const adjust = new AdjustAssetUrls(); |
| 138 | + // we check for the resolve throw as this private import does not exists => |
| 139 | + // which means if a not resolve related error in our code happens the test fails |
| 140 | + await expectThrowsAsync( |
| 141 | + () => adjust.transform('<img src="resolve:#src/logo.svg" />', options), |
| 142 | + { |
| 143 | + errorMatch: /Cannot find module '#src\/logo\.svg'/, |
| 144 | + }, |
| 145 | + ); |
| 146 | + }); |
107 | 147 | }); |
0 commit comments