public override void Specify() { given("a script which echoes args", delegate() { var script = @" require(['env!env/args'], function (args) { for(var i = 0; i < args.length; i++) { ioe.print(args[i]); } }); "; when("jslib\\YUNoarg\\args.js is ran with the script", delegate() { var context = new CompilerUsage(this); arrange(delegate { context.compiler.LoadResource(@"build\jslib\yunoamd\args.js"); context.compiler.RunWithArguments(script, new [] { "1", 23.ToString(), "456" }); }); it("echoes the arguments", delegate() { context.ExpectLines("1", "23", "456"); }); }); }); }
public override void Specify() { describe("the file module provided for node only needs fs and path", delegate() { var testFolder = new TestFolder(this); var context = new CompilerUsage(this, testFolder.FullName); var fileToWrite = arrange(() => Path.Combine(testFolder.FullName, "file.txt")); it("allows path to be used", delegate() { var script = @" require(['env!env/args', 'file'], function (args, file) { file.saveUtf8File(args[0], 'hello, world'); }); "; expect(() => !File.Exists(fileToWrite)); context.compiler.RunWithArguments(script, new[] { fileToWrite }); expect(() => File.ReadAllText(fileToWrite) == "hello, world"); }); }); }
public override void Specify() { var context = new CompilerUsage(this); describe("warn", delegate() { it("writes a warning to the console", delegate() { context.compiler.Evaluate("ioe.warn('message',1,'source.js', 3)"); context.ExpectLines("WARNING: source.js:1:3 message"); }); }); }
public override void Specify() { var context = new CompilerUsage(this); it("writes the message to the console", delegate() { context.compiler.Evaluate("require(['print'], function(print) { print('123'); });"); context.ExpectLines("123"); }); it("writes multiple messages to the console", delegate() { context.compiler.Evaluate("require(['print'], function(print) { print('123', '456', '789'); });"); context.ExpectLines("123", "456", "789"); }); }
public override void Specify() { var testFolder = new TestFolder(this); var context = new CompilerUsage(this, testFolder.FullName); it("supports existsSync", delegate() { var otherFile = Path.Combine(testFolder.FullName, "someOtherFile.txt"); File.WriteAllText(otherFile, "foo"); var otherfolder = Path.Combine(testFolder.FullName, "RabOof"); var script = @" require(['path', 'print'], function(path, print) { print(path.existsSync(" + Serialize(testFolder.FullName) + @")); print(path.existsSync(" + Serialize(otherfolder) + @")); print(path.existsSync(" + Serialize(otherFile) + @")); });"; context.compiler.Execute(script); context.ExpectLines("True", "False", "True"); }); it("supports normalize", delegate() { var further = Path.Combine(testFolder.FullName, "turtles\\turtles\\alltheway.txt"); var expected = further.ToLower(); var script = @" require(['path', 'print'], function(path, print) { print(path.normalize('.\\turtles\\turtles\\alltheway.txt')); print(path.normalize('.\\turtles\\turtles\\..\\turtles\\alltheway.txt')); print(path.normalize('TuRtLeS\\tUrTlEs\\alltheway.txt')); print(path.normalize(" + Serialize(further) + @")); });"; context.compiler.Execute(script); context.ExpectLines(expected, expected, expected, expected); }); it("supports join", delegate() { var script = @" require(['path', 'print'], function(path, print) { print(path.join('c:\\test')); print(path.join('c:\\test', 'second')); print(path.join('c:\\test', 'second\\')); print(path.join('c:\\test', 'second', 'third')); });"; context.compiler.Execute(script); context.ExpectLines(@"c:\test",@"c:\test\second",@"c:\test\second\",@"c:\test\second\third"); }); it("supports dirname", delegate() { var otherFile = Path.Combine(testFolder.FullName, "foo\\bar\\baz.txt"); var script = @" require(['path', 'print'], function(path, print) { var topPath = path.dirname(" + Serialize(otherFile)+ @"); print(topPath); var secondPath = path.dirname(topPath); print(secondPath); });"; context.compiler.Execute(script); string topPath = new FileInfo(otherFile).DirectoryName; string secondPath = new FileInfo(topPath).DirectoryName; context.ExpectLines(topPath,secondPath); }); }
public override void Specify() { var testFolder = new TestFolder(this); var context = new CompilerUsage(this, testFolder.FullName); var expectedContent = Guid.NewGuid().ToString(); string relativeTargetPath = @"la\de\da\wrote.txt"; var targetPath = arrange(() => Path.Combine(testFolder.FullName, relativeTargetPath)); var writeScript = arrange(() => "require(['fs'], function(fs) { fs.writeFileSync( " + Serialize(targetPath) + ", " + Serialize(expectedContent) + ",'utf8'); });"); it("supports writeFileSync", delegate() { context.compiler.Execute(writeScript); expect(() => File.ReadAllText(targetPath) == expectedContent); }); it("supports readFileSync", delegate() { context.compiler.Execute(writeScript); var echoScript = arrange(() => "require(['fs', 'print'], function(fs, print) { print(fs.readFileSync( " + Serialize(targetPath) + ",'utf8')); });"); context.compiler.Execute(echoScript); context.ExpectLines(expectedContent); }); it("supports mkdirSync", delegate() { var otherDirectory = Path.Combine(testFolder.FullName, "CreatedByNativeFS"); expect(() => !Directory.Exists(otherDirectory)); var echoScript = "require(['fs'], function(fs) { fs.mkdirSync( " + Serialize(otherDirectory) + ",'0777'); });"; context.compiler.Execute(echoScript); expect(() => Directory.Exists(otherDirectory)); }); it("supports rmdirSync", delegate() { var otherDirectory = Path.Combine(testFolder.FullName, "CreatedByNativeFS"); Directory.CreateDirectory(otherDirectory); expect(() => Directory.Exists(otherDirectory)); var script = "require(['fs'], function(fs) { fs.rmdirSync( " + Serialize(otherDirectory) + "); });"; context.compiler.Execute(script); expect(() => !Directory.Exists(otherDirectory)); }); it("supports unlinkSync", delegate() { context.compiler.Execute(writeScript); expect(() => File.Exists(targetPath)); var script = "require(['fs'], function(fs) { fs.unlinkSync( " + Serialize(targetPath) + "); });"; context.compiler.Execute(script); expect(() => !File.Exists(targetPath)); }); foreach (var pathVariation in new[] { relativeTargetPath, ".\\" + relativeTargetPath }) { it("supports realpathSync for " + pathVariation, delegate() { context.compiler.Execute(writeScript); var realScript = "require(['fs', 'print'], function(fs, print) { print(fs.realpathSync( " + Serialize(pathVariation) + ",'utf8')); });"; context.compiler.Execute(realScript); context.ExpectLines(targetPath); }); } describe("statSync", delegate() { foreach (var expression in new Dictionary<string, string>() { {"fileStats.isFile()", "True"}, {"dirStats.isFile()", "False"}, {"fileStats.isDirectory()", "False"}, {"dirStats.isDirectory()", "True"} }) it("evalutes expression " + expression.Key + " as " + expression.Value, delegate() { context.compiler.Execute(writeScript); var statScript = @" require(['fs', 'print'], function(fs, print) { var fileStats = fs.statSync(" + Serialize(targetPath) + @"); var dirStats = fs.statSync(" + Serialize(new FileInfo(targetPath).Directory.FullName) + @"); print(" + expression.Key + @"); });"; context.compiler.Execute(statScript); context.ExpectLines(expression.Value); }); it("reports last modified time", delegate() { var before = (double)DateTime.UtcNow.ToFileTimeUtc(); context.compiler.Execute(writeScript); var after = (double)DateTime.UtcNow.ToFileTimeUtc(); var statScript = @" require(['fs', 'print'], function(fs, print) { var fileStats = fs.statSync(" + Serialize(targetPath) + @"); print(fileStats.mtime.getTime()); });"; context.compiler.Execute(statScript); var time = double.Parse(context.GetLines().Single()); expect(() => before <= time && time <= after); }); }); describe("readdirSync", delegate() { it("lists file and directory names", delegate() { Directory.CreateDirectory(Path.Combine(testFolder.FullName, "qux")); File.WriteAllText(Path.Combine(testFolder.FullName, "foo.txt"), "123"); File.WriteAllText(Path.Combine(testFolder.FullName, "bar.html"), "123"); File.WriteAllText(Path.Combine(testFolder.FullName, "baz.css"), "123"); var readdirScript = @" require(['fs', 'print'], function(fs, print) { var names = fs.readdirSync(" + Serialize(testFolder.FullName) + @"); print.apply(null, names); });"; context.compiler.Execute(readdirScript); context.ExpectLines("bar.html", "baz.css", "foo.txt", "qux"); }); }); }