Ejemplo n.º 1
0
        public void BundleComplexStructure()
        {
            var bundleId = "bundle1";
            var bundleOutputFolder = @"c:\bundles";
            var filesPaths = new List<string>(new[] { @"TestData\ParseConfigsShould\LoadAComplexDependencyTree.json" });
            var entrypointOverride = "";

            var expectedBundle = new RequireJsNet.Compressor.Bundle()
            {
                BundleId = bundleId,
                ContainingConfig = filesPaths[0],
                Output = $"{bundleOutputFolder}\\{bundleId}.js",
                Files = new List<RequireJsNet.Compressor.FileSpec>(new[] {
                    TestData.FileSpecs.Scripts_BundleIncludedDirectory_a(projectPath),
                    TestData.FileSpecs.Scripts_BundleIncludedDirectory_b(projectPath),
                    TestData.FileSpecs.Scripts_c(projectPath),
                    TestData.FileSpecs.Scripts_b(projectPath),
                    TestData.FileSpecs.Scripts_a(projectPath)
                })
            };

            var compressor = new RequireJsNet.Compressor.RequireProcessing.AutoBundleConfigProcessor(projectPath, bundleOutputFolder, entrypointOverride, filesPaths, System.Text.Encoding.UTF8);
            var actualBundles = compressor.ParseConfigs();

            Assert.Equal(1, actualBundles.Count);
            AssertEqual(expectedBundle, actualBundles[0]);
        }
Ejemplo n.º 2
0
        public void MakeCorrectRelativePathWhenDependedFileRequiresUpwardsInTree()
        {
            var bundleId           = "bundle5";
            var bundleOutputFolder = @"c:\bundles";
            var filesPaths         = new List <string>(new[] { @"TestData\ParseConfigsShould\MakeCorrectRelativePathWhenDependedFileRequiresUpwardsInTree.json" });
            var entrypointOverride = projectPath + @"\Scripts\";

            var expectedBundle = new RequireJsNet.Compressor.Bundle()
            {
                BundleId         = bundleId,
                ContainingConfig = filesPaths[0],
                Output           = $"{bundleOutputFolder}\\{bundleId}.js",
                Files            = new List <RequireJsNet.Compressor.FileSpec>(new[] {
                    TestData.FileSpecs.otherscripts_e(projectPath),
                    TestData.FileSpecs.Scripts_MakeCorrectRelativePathWhenDependedFileRequiresUpwardsInTree_g(projectPath),
                    TestData.FileSpecs.Scripts_MakeCorrectRelativePathWhenDependedFileRequiresUpwardsInTree_f(projectPath)
                })
            };

            var compressor    = new RequireJsNet.Compressor.RequireProcessing.AutoBundleConfigProcessor(projectPath, bundleOutputFolder, entrypointOverride, filesPaths, System.Text.Encoding.UTF8);
            var actualBundles = compressor.ParseConfigs();

            Assert.Equal(1, actualBundles.Count);
            AssertEqual(expectedBundle, actualBundles[0]);
        }
Ejemplo n.º 3
0
        public void BundleComplexStructure()
        {
            var bundleId           = "bundle1";
            var bundleOutputFolder = @"c:\bundles";
            var filesPaths         = new List <string>(new[] { @"TestData\ParseConfigsShould\LoadAComplexDependencyTree.json" });
            var entrypointOverride = "";

            var expectedBundle = new RequireJsNet.Compressor.Bundle()
            {
                BundleId         = bundleId,
                ContainingConfig = filesPaths[0],
                Output           = $"{bundleOutputFolder}\\{bundleId}.js",
                Files            = new List <RequireJsNet.Compressor.FileSpec>(new[] {
                    TestData.FileSpecs.Scripts_BundleIncludedDirectory_a(projectPath),
                    TestData.FileSpecs.Scripts_BundleIncludedDirectory_b(projectPath),
                    TestData.FileSpecs.Scripts_c(projectPath),
                    TestData.FileSpecs.Scripts_b(projectPath),
                    TestData.FileSpecs.Scripts_a(projectPath)
                })
            };

            var compressor    = new RequireJsNet.Compressor.RequireProcessing.AutoBundleConfigProcessor(projectPath, bundleOutputFolder, entrypointOverride, filesPaths, System.Text.Encoding.UTF8);
            var actualBundles = compressor.ParseConfigs();

            Assert.Equal(1, actualBundles.Count);
            AssertEqual(expectedBundle, actualBundles[0]);
        }
Ejemplo n.º 4
0
        public void InvalidShim()
        {
            var bundleId           = "bundle2";
            var bundleOutputFolder = @"c:\bundles";
            var testFilePaths      = new List <string>(new[] {
                @"TestData\ParseConfigsShould\InvalidShim1.json",
                @"TestData\ParseConfigsShould\InvalidShim2.json",
                @"TestData\ParseConfigsShould\InvalidShim3.json",
                @"TestData\ParseConfigsShould\InvalidShim4.json",
                @"TestData\ParseConfigsShould\InvalidShim5.json",
                @"TestData\ParseConfigsShould\InvalidShim6.json",
                @"TestData\ParseConfigsShould\InvalidShim7.json",
                @"TestData\ParseConfigsShould\InvalidShim8.json",
            });
            var entrypointOverride = "";

            foreach (var filePath in testFilePaths)
            {
                var expectedBundle = new RequireJsNet.Compressor.Bundle()
                {
                    BundleId         = bundleId,
                    ContainingConfig = filePath,
                    Output           = $"{bundleOutputFolder}\\{bundleId}.js",
                    Files            = new List <RequireJsNet.Compressor.FileSpec>(new[] {
                        TestData.FileSpecs.Scripts_BundleIncludedDirectory_a(projectPath)
                    })
                };

                var compressor = new RequireJsNet.Compressor.RequireProcessing.AutoBundleConfigProcessor(projectPath, bundleOutputFolder, entrypointOverride, new List <string>(new string[] { filePath }), System.Text.Encoding.UTF8);
                Assert.Throws <JsonReaderException>(() =>
                {
                    compressor.ParseConfigs();
                });
            }
        }
Ejemplo n.º 5
0
        private static void AssertEqual(RequireJsNet.Compressor.Bundle expected, RequireJsNet.Compressor.Bundle actual)
        {
            Assert.Equal(expected.BundleId, actual.BundleId);
            Assert.Equal(expected.ContainingConfig, actual.ContainingConfig);
            Assert.Equal(expected.Output, actual.Output);

            Assert.Equal(expected.Files.Count, actual.Files.Count);
            for (var i = 0; i < expected.Files.Count; i++)
            {
                AssertEqual(expected.Files[i], actual.Files[i]);
            }
        }
Ejemplo n.º 6
0
        public void LoadModuleThatExportsDefault()
        {
            var bundleId           = "bundle1";
            var bundleOutputFolder = @"c:\bundles";
            var filesPaths         = new List <string>(new[] { projectPath + @"\LoadModuleThatExportsDefault.json" });
            var entrypointOverride = "";

            var expectedBundle = new RequireJsNet.Compressor.Bundle()
            {
                BundleId         = bundleId,
                ContainingConfig = filesPaths[0],
                Output           = $"{bundleOutputFolder}\\{bundleId}.js",
                Files            = new List <RequireJsNet.Compressor.FileSpec>(new[] {
                    TestData.FileSpecs.Scripts_exportdefault(projectPath)
                })
            };

            var compressor    = new RequireJsNet.Compressor.RequireProcessing.AutoBundleConfigProcessor(projectPath, bundleOutputFolder, entrypointOverride, filesPaths, System.Text.Encoding.UTF8);
            var actualBundles = compressor.ParseConfigs();

            Assert.Equal(1, actualBundles.Count);
            AssertEqual(expectedBundle, actualBundles[0]);
        }
Ejemplo n.º 7
0
        public void FindShimWithPath()
        {
            var bundleId           = "bundle3";
            var bundleOutputFolder = @"c:\bundles";
            var filesPaths         = new List <string>(new[] { @"TestData\ParseConfigsShould\FindShimWithPath.json" });
            var entrypointOverride = "";

            var expectedBundle = new RequireJsNet.Compressor.Bundle()
            {
                BundleId         = bundleId,
                ContainingConfig = filesPaths[0],
                Output           = $"{bundleOutputFolder}\\{bundleId}.js",
                Files            = new List <RequireJsNet.Compressor.FileSpec>(new[] {
                    TestData.FileSpecs.Scripts_d_pathed_as_nextfile(projectPath),
                    TestData.FileSpecs.Scripts_shimmed_pathed_as_thefile(projectPath)
                })
            };

            var compressor    = new RequireJsNet.Compressor.RequireProcessing.AutoBundleConfigProcessor(projectPath, bundleOutputFolder, entrypointOverride, filesPaths, System.Text.Encoding.UTF8);
            var actualBundles = compressor.ParseConfigs();

            Assert.Equal(1, actualBundles.Count);
            AssertEqual(expectedBundle, actualBundles[0]);
        }
Ejemplo n.º 8
0
        public void BundleIncludedNonexistentFileWithPath()
        {
            var bundleId           = "bundle2";
            var bundleOutputFolder = @"c:\bundles";
            var filesPaths         = new List <string>(new[] { @"TestData\ParseConfigsShould\BundleIncludedNonexistentFileWithPath.json" });
            var entrypointOverride = "";

            var expectedBundle = new RequireJsNet.Compressor.Bundle()
            {
                BundleId         = bundleId,
                ContainingConfig = filesPaths[0],
                Output           = $"{bundleOutputFolder}\\{bundleId}.js",
                Files            = new List <RequireJsNet.Compressor.FileSpec>(new[] {
                    TestData.FileSpecs.Scripts_BundleIncludedDirectory_a(projectPath)
                })
            };

            var compressor = new RequireJsNet.Compressor.RequireProcessing.AutoBundleConfigProcessor(projectPath, bundleOutputFolder, entrypointOverride, filesPaths, System.Text.Encoding.UTF8);

            Assert.Throws <ArgumentException>(() =>
            {
                compressor.ParseConfigs();
            });
        }
Ejemplo n.º 9
0
        public void SupportEC6()
        {
            var bundleId = "bundle5";
            var bundleOutputFolder = @"c:\bundles";
            var filesPaths = new List<string>(new[] { @"TestData\ParseConfigsShould\SupportEC6.json" });
            var entrypointOverride = projectPath + @"\Scripts\";

            var expectedBundle = new RequireJsNet.Compressor.Bundle()
            {
                BundleId = bundleId,
                ContainingConfig = filesPaths[0],
                Output = $"{bundleOutputFolder}\\{bundleId}.js",
                Files = new List<RequireJsNet.Compressor.FileSpec>(new[] {
                    TestData.FileSpecs.Scripts_SupportEC6_h(projectPath)
                })
            };

            var compressor = new RequireJsNet.Compressor.RequireProcessing.AutoBundleConfigProcessor(projectPath, bundleOutputFolder, entrypointOverride, filesPaths, System.Text.Encoding.UTF8);
            var actualBundles = compressor.ParseConfigs();

            Assert.Equal(1, actualBundles.Count);
            AssertEqual(expectedBundle, actualBundles[0]);
        }
Ejemplo n.º 10
0
        public void MakeCorrectRelativePathWhenEntryPointEndsWithDirSeparator()
        {
            var bundleId = "bundle4";
            var bundleOutputFolder = @"c:\bundles";
            var filesPaths = new List<string>(new[] { @"TestData\ParseConfigsShould\UseCorrectModuleRelativePathWhenOutsideBasePath.json" });
            var entrypointOverride = projectPath + @"\Scripts\";

            var expectedBundle = new RequireJsNet.Compressor.Bundle()
            {
                BundleId = bundleId,
                ContainingConfig = filesPaths[0],
                Output = $"{bundleOutputFolder}\\{bundleId}.js",
                Files = new List<RequireJsNet.Compressor.FileSpec>(new[] {
                    TestData.FileSpecs.Scripts_d(projectPath),
                    TestData.FileSpecs.otherscripts_e(projectPath, "'d'")
                })
            };

            var compressor = new RequireJsNet.Compressor.RequireProcessing.AutoBundleConfigProcessor(projectPath, bundleOutputFolder, entrypointOverride, filesPaths, System.Text.Encoding.UTF8);
            var actualBundles = compressor.ParseConfigs();

            Assert.Equal(1, actualBundles.Count);
            AssertEqual(expectedBundle, actualBundles[0]);
        }