| 229 | } |
| 230 | |
| 231 | export async function assertCanCreateKVNamespace() { |
| 232 | const entry = './test/fixtures/worker.js'; |
| 233 | const code = ` |
| 234 | addEventListener('fetch', async e => { |
| 235 | const body = await greetings.get('hello', 'text'); |
| 236 | e.respondWith(new Response(body)); |
| 237 | });`; |
| 238 | await fs.outputFile(entry, code); |
| 239 | await fs.outputFile( |
| 240 | './test/fixtures/greetings.json', |
| 241 | '[{ "key": "hello", "value": "world", "base64": false }]' |
| 242 | ); |
| 243 | const command = new RunCommand({ |
| 244 | entry, |
| 245 | port, |
| 246 | inspect: false, |
| 247 | watch: true, |
| 248 | check: false, |
| 249 | kv: ['./test/fixtures/greetings.json'] |
| 250 | }); |
| 251 | await command.execute(); |
| 252 | const response = await fetch('http://localhost:7000'); |
| 253 | const html = await response.text(); |
| 254 | assert.equal(html, 'world'); |
| 255 | |
| 256 | const updated = new Promise(resolve => |
| 257 | command.host.on('worker-updated', resolve) |
| 258 | ); |
| 259 | await fs.outputFile( |
| 260 | './test/fixtures/greetings.json', |
| 261 | '[{ "key": "hello", "value": "world 2", "base64": false }]' |
| 262 | ); |
| 263 | await updated; |
| 264 | const response2 = await fetch('http://localhost:7000'); |
| 265 | const html2 = await response2.text(); |
| 266 | assert.equal(html2, 'world 2'); |
| 267 | |
| 268 | command.dispose(); |
| 269 | } |