Exemple #1
0
        public static HashSet <string> ListTestFolders(RenderContext context, JsTestOption options)
        {
            HashSet <string> result = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            var root = options.GetDiskRoot(context);

            if (!string.IsNullOrEmpty(options.TestFolder))
            {
                var allsubs = System.IO.Directory.GetDirectories(root, options.TestFolder, System.IO.SearchOption.AllDirectories);

                foreach (var item in allsubs)
                {
                    System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(item);

                    string fullname = info.FullName;
                    fullname = fullname.Substring(root.Length);
                    fullname = fullname.Replace("\\", "/");

                    var path = options.FolderPath(context);

                    if (!string.IsNullOrEmpty(path) && fullname.ToLower().StartsWith(path))
                    {
                        fullname = fullname.Substring(path.Length + 1);
                    }
                    result.Add(fullname);
                }
            }

            return(result);
        }
Exemple #2
0
        public static HashSet <JsFilePath> ListFolderFiles(RenderContext context, JsTestOption option, string Folder)
        {
            HashSet <JsFilePath> result = new HashSet <JsFilePath>();

            var root = option.GetDiskRoot(context);

            var path = option.FolderPath(context);

            if (!string.IsNullOrEmpty(path))
            {
                root = Lib.Helper.IOHelper.CombinePath(root, path);
            }

            if (!string.IsNullOrEmpty(Folder))
            {
                var fullfolder = Lib.Helper.IOHelper.CombinePath(root, Folder);

                if (System.IO.Directory.Exists(fullfolder))
                {
                    var allfiles = System.IO.Directory.GetFiles(fullfolder, "*.js", System.IO.SearchOption.AllDirectories);

                    foreach (var item in allfiles)
                    {
                        System.IO.FileInfo info = new System.IO.FileInfo(item);

                        if (!option.AssertJs.Contains(info.Name))
                        {
                            var jsPath = new JsFilePath();
                            if (!string.IsNullOrEmpty(Folder))
                            {
                                var index = info.FullName.IndexOf(Folder.Replace("/", "\\"), StringComparison.OrdinalIgnoreCase);
                                if (index > -1)
                                {
                                    var relativePath = info.FullName.Substring(index);

                                    jsPath.Folder = System.IO.Path.GetDirectoryName(relativePath);
                                    jsPath.file   = System.IO.Path.GetFileName(relativePath);
                                }
                                else
                                {
                                    jsPath.Folder = Folder;
                                    jsPath.file   = info.Name;
                                }
                            }
                            else
                            {
                                jsPath.file = info.Name;
                            }
                            result.Add(jsPath);
                        }
                    }
                }
            }

            return(result);
        }
Exemple #3
0
        public static HashSet <string> GetReferenceJs(RenderContext context, JsTestOption option, string folder)
        {
            if (string.IsNullOrWhiteSpace(folder) || folder == "\\" || folder == "/")
            {
                return(GetReferenceJs(context, option));
            }

            HashSet <string> result = new HashSet <string>();

            string root = option.GetDiskRoot(context);

            System.IO.DirectoryInfo basedir = new System.IO.DirectoryInfo(root);

            var prepath = option.FolderPath(context);

            if (!string.IsNullOrEmpty(prepath))
            {
                root = Lib.Helper.IOHelper.CombinePath(root, prepath);
            }

            System.IO.DirectoryInfo rootdir = new System.IO.DirectoryInfo(root);

            folder = Lib.Helper.IOHelper.CombinePath(root, folder);

            var currentdir = new System.IO.DirectoryInfo(folder);

            while (currentdir.Exists && currentdir.FullName.Length > rootdir.FullName.Length)
            {
                var file = Lib.Helper.IOHelper.CombinePath(currentdir.FullName, option.JsReferenceFileName);
                if (System.IO.File.Exists(file))
                {
                    var alllines = System.IO.File.ReadAllLines(file);
                    foreach (var line in alllines)
                    {
                        if (line != null)
                        {
                            var lineresult = FindRelativeFileName(basedir, line, currentdir);

                            if (!string.IsNullOrEmpty(lineresult))
                            {
                                result.Add(lineresult);
                            }
                        }
                    }
                }

                currentdir = currentdir.Parent;
            }

            return(result);
        }
Exemple #4
0
        public static HashSet <string> ListFileFunctions(RenderContext context, JsTestOption option, string folder, string file)
        {
            var root = option.GetDiskRoot(context);

            string prepath = option.FolderPath(context);

            if (!string.IsNullOrEmpty(prepath))
            {
                root = Lib.Helper.IOHelper.CombinePath(root, prepath);
            }

            if (!string.IsNullOrEmpty(folder))
            {
                var fullfolder = Lib.Helper.IOHelper.CombinePath(root, folder);
                var fullfile   = Lib.Helper.IOHelper.CombinePath(fullfolder, file);

                var alltext = System.IO.File.ReadAllText(fullfile);
                var block   = GetBlockJs(option, alltext);
                return(Lib.Helper.JintHelper.ListFunctionNames(block));
            }
            return(new HashSet <string>());
        }
Exemple #5
0
        public static void RenderJs(RenderContext Context, JsTestOption option, string root, RenderRespnose response, JsTestCommand command)
        {
            response.ContentType = "application/javascript";

            if (!string.IsNullOrEmpty(command.JsPath))
            {
                string filename = command.JsPath.Replace("/", "\\");

                if (filename.IndexOf("?") > -1)
                {
                    filename = filename.Substring(0, filename.IndexOf("?"));
                }

                if (filename.StartsWith("\\"))
                {
                    filename = filename.Substring(1);
                }

                string fullname = root;
                string prepath  = option.FolderPath(Context);

                if (!string.IsNullOrEmpty(prepath))
                {
                    fullname = IOHelper.CombinePath(root, prepath);
                }

                fullname = IOHelper.CombinePath(fullname, filename);


                if (!System.IO.File.Exists(fullname))
                {
                    // This is to make sure the render of assert js...
                    foreach (var item in option.AssertJs)
                    {
                        if (filename.EndsWith(item))
                        {
                            fullname = System.IO.Path.Combine(Kooboo.Data.AppSettings.RootPath, "/_admin/kbtest/" + item);
                        }
                    }
                }

                if (System.IO.File.Exists(fullname))
                {
                    string baserelarive = GetRelative(prepath, command.JsPath);


                    if (command.Command == JsTestCommand.JsCommand.run)
                    {
                        string retryurl  = string.Empty;
                        string rawfolder = filename;
                        int    lastslash = rawfolder.LastIndexOf("\\");
                        if (lastslash > -1)
                        {
                            string folder     = rawfolder.Substring(0, lastslash);
                            string jsfilename = rawfolder.Substring(lastslash + 1);
                            retryurl = GenerateUrl(option, JsTestCommand.JsCommand.run, folder, jsfilename);
                        }

                        // TODO: Render the k commands.
                        var alltext = IOHelper.ReadAllText(fullname);
                        alltext = RenderServerSide(alltext, root, Context, baserelarive);

                        response.Body = RenderJs(option, alltext, command.Function, retryurl);
                    }
                    else
                    {
                        var alltext = IOHelper.ReadAllText(fullname);
                        alltext = RenderServerSide(alltext, root, Context, baserelarive);

                        response.Body = alltext;
                    }
                }
            }
        }