示例#1
0
        public void Jint_Scripting_InMemoryFiles_Test()
        {
            //Assert.Inconclusive(); return;

            ScriptingContext jsScriptingContext = ScriptingContext.ScriptingContextWithInMemoryFs(ES5_scripts_to_zip_plus_to_encode_in_Base64.GetScripts());

            JsScriptRunner jsScriptRunner = JsScriptRunner.RunnerWithContext(
                JsScriptRunnerType.Jint,
                jsScriptingContext,
                Scripting_TestSettings.ScriptingContextName);

            jsScriptRunner.Run("var exports = {};");                                 // required by the row of 'main.js' ```Object.defineProperty(exports, "__esModule", { value: true });``` generated by TypeScript
            jsScriptRunner.Run(jsScriptingContext.ReadFile("./lib/myrequire.js"));   // load a custom version of 'require'
            jsScriptRunner.Run(jsScriptingContext.ReadFile("main.js"));              // execute script from virtual FS (would have been the same executing "./main.js")
            Assert.AreEqual("Hello World", jsScriptingContext.ReadFile("filename")); // test output of Js scripts
        }
示例#2
0
        public void ClearScript_Scripting_RealFs_Test()
        {
            //Assert.Inconclusive(); return;

            Result <string> scriptsPath = FileIO.SearchAFolderAboveTheCurrentDirectoryOfTheApplication(Scripting_TestSettings.ScriptsPath_Tests); // find the folder with the scripts

            if (scriptsPath.IsFailure)
            {
                throw new InvalidOperationException("scripts folder not found");
            }

            ScriptingContext jsScriptingContext = ScriptingContext.ScriptingContextWithRealFs(Path.Combine(scriptsPath.Value, Scripting_TestSettings.ScriptsPath_Tests_ES6));

            JsScriptRunner jsScriptRunner = JsScriptRunner.RunnerWithContext(
                JsScriptRunnerType.ClearScript,
                jsScriptingContext,
                Scripting_TestSettings.ScriptingContextName);

            jsScriptRunner.Run("var exports = {};");                                 // required by the row of 'main.js' ```Object.defineProperty(exports, "__esModule", { value: true });``` generated by TypeScript
            jsScriptRunner.Run(jsScriptingContext.ReadFile("./lib/myrequire.js"));   // load a custom version of 'require'
            jsScriptRunner.Run(jsScriptingContext.ReadFile("main.js"));              // execute script from virtual FS (would have been the same executing "./main.js")
            Assert.AreEqual("Hello World", jsScriptingContext.ReadFile("filename")); // test output of Js scripts
        }