|
| 1 | +/* eslint-disable no-template-curly-in-string */ |
| 2 | +import {getTester} from './utils/test.mjs'; |
| 3 | + |
| 4 | +const {test} = getTester(import.meta); |
| 5 | + |
| 6 | +test.snapshot({ |
| 7 | + valid: [ |
| 8 | + 'URL("./foo", base)', |
| 9 | + 'new URL(...["./foo"], base)', |
| 10 | + 'new URL(["./foo"], base)', |
| 11 | + 'new URL("./foo")', |
| 12 | + 'new URL("./foo", base, extra)', |
| 13 | + 'new URL("./foo", ...[base])', |
| 14 | + 'new NOT_URL("./foo", base)', |
| 15 | + 'new URL', |
| 16 | + // Not checking this case |
| 17 | + 'new globalThis.URL("./foo", base)', |
| 18 | + 'const foo = "./foo"; new URL(foo, base)', |
| 19 | + 'const foo = "/foo"; new URL(`.${foo}`, base)', |
| 20 | + 'new URL(`.${foo}`, base)', |
| 21 | + 'new URL(".", base)', |
| 22 | + 'new URL(".././foo", base)', |
| 23 | + // We don't check cooked value |
| 24 | + 'new URL(`\\u002E/${foo}`, base)', |
| 25 | + // We don't check escaped string |
| 26 | + 'new URL("\\u002E/foo", base)', |
| 27 | + 'new URL(\'\\u002E/foo\', base)', |
| 28 | + ], |
| 29 | + invalid: [ |
| 30 | + 'new URL("./foo", base)', |
| 31 | + 'new URL(\'./foo\', base)', |
| 32 | + 'new URL("./", base)', |
| 33 | + 'new URL("././a", base)', |
| 34 | + 'new URL(`./${foo}`, base)', |
| 35 | + ], |
| 36 | +}); |
| 37 | + |
| 38 | +const alwaysAddDotSlashOptions = ['always']; |
| 39 | +test.snapshot({ |
| 40 | + valid: [ |
| 41 | + 'URL("foo", base)', |
| 42 | + 'new URL(...["foo"], base)', |
| 43 | + 'new URL(["foo"], base)', |
| 44 | + 'new URL("foo")', |
| 45 | + 'new URL("foo", base, extra)', |
| 46 | + 'new URL("foo", ...[base])', |
| 47 | + 'new NOT_URL("foo", base)', |
| 48 | + '/* 2 */ new URL', |
| 49 | + // Not checking this case |
| 50 | + 'new globalThis.URL("foo", base)', |
| 51 | + 'new URL(`${foo}`, base2)', |
| 52 | + 'new URL(`.${foo}`, base2)', |
| 53 | + 'new URL(".", base2)', |
| 54 | + 'new URL("//example.org", "https://example.com")', |
| 55 | + 'new URL("//example.org", "ftp://example.com")', |
| 56 | + 'new URL("ftp://example.org", "https://example.com")', |
| 57 | + 'new URL("https://example.org:65536", "https://example.com")', |
| 58 | + 'new URL("/", base)', |
| 59 | + 'new URL("/foo", base)', |
| 60 | + 'new URL("../foo", base)', |
| 61 | + 'new URL(".././foo", base)', |
| 62 | + 'new URL("C:\\foo", base)', |
| 63 | + 'new URL("\\u002E/foo", base)', |
| 64 | + 'new URL("\\u002Ffoo", base)', |
| 65 | + ].map(code => ({code, options: alwaysAddDotSlashOptions})), |
| 66 | + invalid: [ |
| 67 | + 'new URL("foo", base)', |
| 68 | + 'new URL(\'foo\', base)', |
| 69 | + ].map(code => ({code, options: alwaysAddDotSlashOptions})), |
| 70 | +}); |
0 commit comments