~endlessm/jasmine-gjs/trunk

« back to all changes in this revision

Viewing changes to src/jasmineBoot.js

  • Committer: Philip Chimento
  • Date: 2020-08-25 05:15:50 UTC
  • Revision ID: git-v1:4723ba903072957a060b6ed17613c57e40d48f3e
Load spec files with the same name in different directories

The importer will cache imports with the same name, so we need to make a
fresh copy of the importer with `imports['.']` each time we load a spec
file, in case it has the same name as a preceding spec file.

Closes: #11

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
 
68
68
    loadSpecs() {
69
69
        const oldSearchPath = imports.searchPath.slice();  // make a copy
 
70
        let specImporter = imports['.'];
70
71
        this.specFiles.forEach(function (file) {
71
72
            const modulePath = GLib.path_get_dirname(file);
72
73
            const moduleName = GLib.path_get_basename(file).slice(0, -3);  // .js
 
74
 
 
75
            // Backwards compatibility - let specs import modules from their own
 
76
            // directories
73
77
            imports.searchPath.unshift(modulePath);
74
 
            void imports[moduleName];
 
78
            specImporter.searchPath.unshift(modulePath);
 
79
            void specImporter[moduleName];
75
80
            imports.searchPath = oldSearchPath;
 
81
 
 
82
            // Make a new copy of the importer in case we need to import another
 
83
            // spec with the same filename, so it is not cached
 
84
            specImporter = specImporter['.'];
76
85
        });
77
86
    }
78
87