change requireJS from adding the .js file extension automatically on intern.js

171 Views Asked by At

Currently I am working in custom html reporter for intern.js. The Templating engine that i am using is marko.js. marko.js have extension file with ".marko" for me to input my html syntax The file is generated correctly in normal node.js (common.js)

The issue occurred when i integrate the same code to intern.js. The requirejs(AMD) that use by internjs is adding the .js file extension automatically to my marko extension when i do

var template = require('./hello-world.marko');

which make the file become hello-world.marko.js and this caused the code broke in markojs

the custom html reporter code is below

define(function (require) {

    // require('intern/dojo/node!marko/node-require').install();
    var fs = require('intern/dojo/node!fs');

    var template = require('./hello-world.marko');
    console.log(template);
    function JsonReporter(config) {
        config = config || {};
        this.output = config.output;
    }

    JsonReporter.prototype = {
        runEnd(executor) {
            // console.log("toJson: " + JSON.stringify(executor.suites))
            data = JSON.stringify(executor.suites);
            template.renderToString(data,
                function (err, output) {
                    console.log(output);
                    fs.writeFile('result.html', output, function (err) {
                        if (err) return console.log(err);
                        console.log('Save done');
                    });
                });
        },
    }
    return JsonReporter;

})
1

There are 1 best solutions below

0
On

The require function isn't really meant for loading arbitrary text resources in either Node's loader or an AMD loader. In Node, whether you're running Intern or not, you can use fs.readFile or fs.readFileSync. In Intern's Dojo-based AMD environment you can also use the dojo/text loader plugin, like this:

var template = require('dojo/text!./hello-world.marko');