Feat: es modules (#139)
* All file imports change from commonjs to es-module * Improved plex error responses back from api * Converted viewHistory to es module * Es-module requires file extension, updated all imports * Fix esmodule not having __dirname defined in scope * Replace dynamic-require with fs readFileSync * Short message service module function is exported as default * Resolved lint issues & ignore import/extension rule until typescript * All tests file imports changed from commonjs to es-module * Import json fixtures with new helper
This commit is contained in:
		
							
								
								
									
										23
									
								
								tests/helpers/importFixture.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								tests/helpers/importFixture.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
import fs from "fs";
 | 
			
		||||
import path from "path";
 | 
			
		||||
import { fileURLToPath } from "url";
 | 
			
		||||
 | 
			
		||||
const __filename = fileURLToPath(import.meta.url);
 | 
			
		||||
const __dirname = path.dirname(__filename);
 | 
			
		||||
 | 
			
		||||
function determineLocation(fixtureFilename) {
 | 
			
		||||
  return path.join(__dirname, "..", "fixtures", fixtureFilename);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default function readFixtureContents(fixtureFilename) {
 | 
			
		||||
  const location = determineLocation(fixtureFilename);
 | 
			
		||||
 | 
			
		||||
  let content = {};
 | 
			
		||||
  try {
 | 
			
		||||
    content = JSON.parse(fs.readFileSync(location, { encoding: "utf-8" }));
 | 
			
		||||
  } catch (err) {
 | 
			
		||||
    console.error(`Error loading fixture file at path: ${location}`);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return content;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user