{"library":"office-addin-test-server","title":"Office Add-in Test Server","description":"The `office-addin-test-server` package provides a lightweight local web server specifically designed for testing Office Add-ins. It's a key component within the larger `OfficeDev/Office-Addin-Scripts` ecosystem, offering a framework for add-ins to send test results, which can then be consumed by test runners like Mocha to validate functionality. Currently stable at version 2.0.4, this package facilitates automated testing workflows by acting as a collection point for results from add-in runtime environments. Unlike general-purpose web servers, its differentiation lies in its tight integration with Office Add-in development, simplifying the process of capturing and processing test outcomes from within Office applications.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install office-addin-test-server"],"cli":null},"imports":["import { startServer } from 'office-addin-test-server';","import { stopServer } from 'office-addin-test-server';","import { TestServer } from 'office-addin-test-server';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { TestServer } from 'office-addin-test-server';\nimport * as path from 'path';\n\nasync function runTestServerExample() {\n  const serverPort = 4201; // Choose an available port\n  const resultsPath = path.join(__dirname, 'test-results.json');\n\n  console.log(`Starting Office Add-in Test Server on port ${serverPort}...`);\n  const testServer = new TestServer(serverPort, resultsPath);\n\n  try {\n    await testServer.start();\n    console.log('Test server started. Waiting for results...');\n\n    // Simulate an add-in sending a test result after some time\n    setTimeout(async () => {\n      console.log('Simulating add-in sending a test result...');\n      // In a real scenario, the add-in would post to /results endpoint\n      // e.g., fetch(`https://localhost:${serverPort}/results`, { method: 'POST', body: JSON.stringify({ passed: true, message: 'Simulated test passed' }) });\n\n      const mockResult = { testName: 'MyAddinFeature', status: 'passed', details: 'Functionality check' };\n      // You would typically process results directly from the server's internal mechanisms\n      // For demonstration, we'll log what the server would process.\n      console.log('Mock result processed by server:', mockResult);\n\n      // In a real test runner, you'd retrieve results from `resultsPath` or server events\n      console.log(`Results would be collected and saved to ${resultsPath}.`);\n\n      await testServer.stop();\n      console.log('Test server stopped.');\n    }, 5000);\n\n  } catch (error) {\n    console.error('Failed to run test server example:', error);\n    await testServer.stop(); // Ensure server is stopped even on error\n  }\n}\n\nrunTestServerExample();\n","lang":"typescript","description":"This quickstart demonstrates how to programmatically start and stop the `office-addin-test-server` to receive simulated test results from an Office Add-in. It sets up a local server, waits for a mock result submission, and then gracefully shuts down the server. This pattern is foundational for automated testing of Office Add-ins.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}