import {join, dirname} from "node:path"; import {test, expect} from "@jest/globals"; import {rollup} from "rollup"; import liveReload from "rollup-plugin-livereload"; import {debugPrintOutput, getCode} from "../util/index.ts"; import html from "../../src/index.ts"; import {fileURLToPath} from "node:url"; const __dirname = dirname(fileURLToPath(import.meta.url)); process.chdir(join(__dirname, 'fixtures')); test('live-reload', async () => { const bundle = await rollup({ input: 'index.html', plugins: [ html({ }), liveReload({ verbose: false// this oddly enough prevents it from actually starting the liveserver, which would've left the test to wait indefinatly to close }) ] }); const code = await getCode(bundle); await bundle.close();// Make sure live-reload closes itself debugPrintOutput('live-reload',code); const portRE = /:[0-9]+\/livereload\.js/gi; for(const file of code){ if(file.code && portRE.test(file.code)){ file.code = file.code.replaceAll(portRE,":/livereload.js"); // remove any references to a port } } expect(code).toMatchSnapshot(); }); // TODO various parameters // - format: cjs, iifi, ... // - sourcemap: inline, false, (and the various exotic sourcemap options) // Watch mode tests would be its own dir // ...