|
| 1 | +// Standalone unit test for the yew-version remark logic. |
| 2 | +// Run with: `node src/remark/yewVersionUrls.test.js` (no build / node_modules needed). |
| 3 | +const assert = require('assert') |
| 4 | +const { versionContextFromPath, applyTokens } = require('./yewVersionUrls.core') |
| 5 | + |
| 6 | +const VERSIONS = ['0.23', '0.22', '0.21', '0.20'] |
| 7 | +let passed = 0 |
| 8 | +const check = (name, got, want) => { |
| 9 | + assert.deepStrictEqual( |
| 10 | + got, |
| 11 | + want, |
| 12 | + `${name}\n got: ${JSON.stringify(got)}\n want: ${JSON.stringify(want)}` |
| 13 | + ) |
| 14 | + passed++ |
| 15 | +} |
| 16 | + |
| 17 | +const NEXT = { |
| 18 | + version: '0.23', |
| 19 | + isNext: true, |
| 20 | + display: '0.23', |
| 21 | + dependency: 'git = "https://github.com/yewstack/yew/"', |
| 22 | + api: 'https://yew-rs-api.web.app/next/yew/', |
| 23 | +} |
| 24 | +const V22 = { |
| 25 | + version: '0.22', |
| 26 | + isNext: false, |
| 27 | + display: '0.22', |
| 28 | + dependency: 'version = "0.22"', |
| 29 | + api: 'https://docs.rs/yew/0.22/yew/', |
| 30 | +} |
| 31 | + |
| 32 | +// --- version derivation from path (next / snapshot / i18n) --- |
| 33 | +check( |
| 34 | + 'next (docs/)', |
| 35 | + versionContextFromPath( |
| 36 | + '/repo/website/docs/getting-started/x.mdx', |
| 37 | + VERSIONS |
| 38 | + ), |
| 39 | + NEXT |
| 40 | +) |
| 41 | +check( |
| 42 | + 'versioned 0.22', |
| 43 | + versionContextFromPath( |
| 44 | + '/repo/website/versioned_docs/version-0.22/tutorial/index.mdx', |
| 45 | + VERSIONS |
| 46 | + ), |
| 47 | + V22 |
| 48 | +) |
| 49 | +check( |
| 50 | + 'i18n next (current/)', |
| 51 | + versionContextFromPath( |
| 52 | + '/repo/website/i18n/ja/docusaurus-plugin-content-docs/current/x.mdx', |
| 53 | + VERSIONS |
| 54 | + ), |
| 55 | + NEXT |
| 56 | +) |
| 57 | +check( |
| 58 | + 'i18n versioned 0.22', |
| 59 | + versionContextFromPath( |
| 60 | + '/repo/website/i18n/zh-Hans/docusaurus-plugin-content-docs/version-0.22/x.mdx', |
| 61 | + VERSIONS |
| 62 | + ), |
| 63 | + V22 |
| 64 | +) |
| 65 | + |
| 66 | +// --- token substitution: next uses git dep + preview host; snapshots use version + docs.rs --- |
| 67 | +const next = versionContextFromPath('/w/website/docs/x.mdx', VERSIONS) |
| 68 | +const v22 = versionContextFromPath( |
| 69 | + '/w/website/versioned_docs/version-0.22/x.mdx', |
| 70 | + VERSIONS |
| 71 | +) |
| 72 | + |
| 73 | +check( |
| 74 | + 'dependency (next -> git)', |
| 75 | + applyTokens('yew = { {{yew_dependency}}, features = ["csr"] }', next), |
| 76 | + 'yew = { git = "https://github.com/yewstack/yew/", features = ["csr"] }' |
| 77 | +) |
| 78 | +check( |
| 79 | + 'dependency (0.22 -> version)', |
| 80 | + applyTokens('yew = { {{yew_dependency}}, features = ["csr"] }', v22), |
| 81 | + 'yew = { version = "0.22", features = ["csr"] }' |
| 82 | +) |
| 83 | +check( |
| 84 | + 'api link (next -> preview host)', |
| 85 | + applyTokens('[use_future]({{yew_api}}suspense/fn.use_future.html)', next), |
| 86 | + '[use_future](https://yew-rs-api.web.app/next/yew/suspense/fn.use_future.html)' |
| 87 | +) |
| 88 | +check( |
| 89 | + 'api link (0.22 -> docs.rs)', |
| 90 | + applyTokens('[use_future]({{yew_api}}suspense/fn.use_future.html)', v22), |
| 91 | + '[use_future](https://docs.rs/yew/0.22/yew/suspense/fn.use_future.html)' |
| 92 | +) |
| 93 | +check( |
| 94 | + 'version token (next)', |
| 95 | + applyTokens('targets Yew {{yew_version}}', next), |
| 96 | + 'targets Yew 0.23' |
| 97 | +) |
| 98 | +check( |
| 99 | + 'version token (0.22)', |
| 100 | + applyTokens('targets Yew {{yew_version}}', v22), |
| 101 | + 'targets Yew 0.22' |
| 102 | +) |
| 103 | +check('passthrough (no token)', applyTokens('plain text', next), 'plain text') |
| 104 | + |
| 105 | +console.log(`ok — ${passed} assertions passed`) |
0 commit comments