Refactor import/setup blocks for tests

Created on 10 July 2023, 12 months ago
Updated 31 July 2023, 11 months ago

Need a common file that sets up tests so there is less copy/paste of imports and other variables.

πŸ“Œ Task
Status

Closed: won't fix

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States aangel

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @aangel
  • Status changed to Closed: won't fix 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States aangel

    There appear to be two ways of doing this:

    The first is to read then eval a file:

    const fs = require('fs');
    
    fs.readFile('myFile.js', 'utf8', function(err, data) {
        if (err) throw err;
    
        const codeToAppend = "\nconsole.log('Hello, World!');";
    
        const newCode = data + codeToAppend;
    
        eval(newCode);
    });
    

    The second is to make an module that contains just imports:

    imports.js:
    import fs from 'fs';
    import path from 'path';
    import express from 'express';
    
    export { fs, path, express };
    
    New file:
    import { fs, path, express } from './imports.js';

    But that doesn't seem to make things measurably (much) easier since all modules have to be named in the import anyway. Must as well just include the import line that specifies the path.

    At this point, since I'm not seeing this as being very valuable, I'm closing it.

Production build 0.69.0 2024