|
| 1 | +/** |
| 2 | + * Copyright (c) 2015-present, Facebook, Inc. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + */ |
| 7 | + |
| 8 | +'use strict'; |
| 9 | + |
| 10 | +const getPublicUrlOrPath = require('../getPublicUrlOrPath'); |
| 11 | + |
| 12 | +const tests = [ |
| 13 | + // DEVELOPMENT with homepage |
| 14 | + { dev: true, homepage: '/', expect: '/' }, |
| 15 | + { dev: true, homepage: '/test', expect: '/test/' }, |
| 16 | + { dev: true, homepage: '/test/', expect: '/test/' }, |
| 17 | + { dev: true, homepage: './', expect: '/' }, |
| 18 | + { dev: true, homepage: '../', expect: '/' }, |
| 19 | + { dev: true, homepage: '../test', expect: '/' }, |
| 20 | + { dev: true, homepage: './test/path', expect: '/' }, |
| 21 | + { dev: true, homepage: 'https://create-react-app.dev/', expect: '/' }, |
| 22 | + { |
| 23 | + dev: true, |
| 24 | + homepage: 'https://create-react-app.dev/test', |
| 25 | + expect: '/test/', |
| 26 | + }, |
| 27 | + // DEVELOPMENT with publicURL |
| 28 | + { dev: true, publicUrl: '/', expect: '/' }, |
| 29 | + { dev: true, publicUrl: '/test', expect: '/test/' }, |
| 30 | + { dev: true, publicUrl: '/test/', expect: '/test/' }, |
| 31 | + { dev: true, publicUrl: './', expect: '/' }, |
| 32 | + { dev: true, publicUrl: '../', expect: '/' }, |
| 33 | + { dev: true, publicUrl: '../test', expect: '/' }, |
| 34 | + { dev: true, publicUrl: './test/path', expect: '/' }, |
| 35 | + { dev: true, publicUrl: 'https://create-react-app.dev/', expect: '/' }, |
| 36 | + { |
| 37 | + dev: true, |
| 38 | + publicUrl: 'https://create-react-app.dev/test', |
| 39 | + expect: '/test/', |
| 40 | + }, |
| 41 | + // DEVELOPMENT with publicURL and homepage |
| 42 | + { dev: true, publicUrl: '/', homepage: '/test', expect: '/' }, |
| 43 | + { dev: true, publicUrl: '/test', homepage: '/path', expect: '/test/' }, |
| 44 | + { dev: true, publicUrl: '/test/', homepage: '/test/path', expect: '/test/' }, |
| 45 | + { dev: true, publicUrl: './', homepage: '/test', expect: '/' }, |
| 46 | + { dev: true, publicUrl: '../', homepage: '/test', expect: '/' }, |
| 47 | + { dev: true, publicUrl: '../test', homepage: '/test', expect: '/' }, |
| 48 | + { dev: true, publicUrl: './test/path', homepage: '/test', expect: '/' }, |
| 49 | + { |
| 50 | + dev: true, |
| 51 | + publicUrl: 'https://create-react-app.dev/', |
| 52 | + homepage: '/test', |
| 53 | + expect: '/', |
| 54 | + }, |
| 55 | + { |
| 56 | + dev: true, |
| 57 | + publicUrl: 'https://create-react-app.dev/test', |
| 58 | + homepage: '/path', |
| 59 | + expect: '/test/', |
| 60 | + }, |
| 61 | + |
| 62 | + // PRODUCTION with homepage |
| 63 | + { dev: false, homepage: '/', expect: '/' }, |
| 64 | + { dev: false, homepage: '/test', expect: '/test/' }, |
| 65 | + { dev: false, homepage: '/test/', expect: '/test/' }, |
| 66 | + { dev: false, homepage: './', expect: './' }, |
| 67 | + { dev: false, homepage: '../', expect: '../' }, |
| 68 | + { dev: false, homepage: '../test', expect: '../test/' }, |
| 69 | + { dev: false, homepage: './test/path', expect: './test/path/' }, |
| 70 | + { dev: false, homepage: 'https://create-react-app.dev/', expect: '/' }, |
| 71 | + { |
| 72 | + dev: false, |
| 73 | + homepage: 'https://create-react-app.dev/test', |
| 74 | + expect: '/test/', |
| 75 | + }, |
| 76 | + // PRODUCTION with publicUrl |
| 77 | + { dev: false, publicUrl: '/', expect: '/' }, |
| 78 | + { dev: false, publicUrl: '/test', expect: '/test/' }, |
| 79 | + { dev: false, publicUrl: '/test/', expect: '/test/' }, |
| 80 | + { dev: false, publicUrl: './', expect: './' }, |
| 81 | + { dev: false, publicUrl: '../', expect: '../' }, |
| 82 | + { dev: false, publicUrl: '../test', expect: '../test/' }, |
| 83 | + { dev: false, publicUrl: './test/path', expect: './test/path/' }, |
| 84 | + { |
| 85 | + dev: false, |
| 86 | + publicUrl: 'https://create-react-app.dev/', |
| 87 | + expect: 'https://create-react-app.dev/', |
| 88 | + }, |
| 89 | + { |
| 90 | + dev: false, |
| 91 | + publicUrl: 'https://create-react-app.dev/test', |
| 92 | + expect: 'https://create-react-app.dev/test/', |
| 93 | + }, |
| 94 | + // PRODUCTION with publicUrl and homepage |
| 95 | + { dev: false, publicUrl: '/', homepage: '/test', expect: '/' }, |
| 96 | + { dev: false, publicUrl: '/test', homepage: '/path', expect: '/test/' }, |
| 97 | + { dev: false, publicUrl: '/test/', homepage: '/test/path', expect: '/test/' }, |
| 98 | + { dev: false, publicUrl: './', homepage: '/test', expect: './' }, |
| 99 | + { dev: false, publicUrl: '../', homepage: '/test', expect: '../' }, |
| 100 | + { dev: false, publicUrl: '../test', homepage: '/test', expect: '../test/' }, |
| 101 | + { |
| 102 | + dev: false, |
| 103 | + publicUrl: './test/path', |
| 104 | + homepage: '/test', |
| 105 | + expect: './test/path/', |
| 106 | + }, |
| 107 | + { |
| 108 | + dev: false, |
| 109 | + publicUrl: 'https://create-react-app.dev/', |
| 110 | + homepage: '/test', |
| 111 | + expect: 'https://create-react-app.dev/', |
| 112 | + }, |
| 113 | + { |
| 114 | + dev: false, |
| 115 | + publicUrl: 'https://create-react-app.dev/test', |
| 116 | + homepage: '/path', |
| 117 | + expect: 'https://create-react-app.dev/test/', |
| 118 | + }, |
| 119 | +]; |
| 120 | + |
| 121 | +describe('getPublicUrlOrPath', () => { |
| 122 | + tests.forEach(t => |
| 123 | + it(JSON.stringify(t), () => { |
| 124 | + const actual = getPublicUrlOrPath(t.dev, t.homepage, t.publicUrl); |
| 125 | + expect(actual).toBe(t.expect); |
| 126 | + }) |
| 127 | + ); |
| 128 | +}); |
0 commit comments