Пример #1
0
    public void ShouldCorrectlyBundle(BundlerTestData testData)
    {
        var outFiles = BundlerTestCore(testData);

        foreach (var(name, genContent) in outFiles)
        {
            var expected = testData.InputContent.TryGetValue("out/" + name, out var content) ? content : "";
            Assert.Equal(expected, genContent);
        }
    }
Пример #2
0
    public static Dictionary <string, string> BundlerTestCore(BundlerTestData testData)
    {
        var output  = new Dictionary <string, string>();
        var bundler = new BundlerImpl(new BundlerCtx(testData, output, "cbm-"));

        bundler.Mangle          = true;
        bundler.CompressOptions = CompressOptions.Default;
        bundler.OutputOptions   = new() { Beautify = true };
        InitCommonParts(testData);
        bundler.Run();

        bundler                 = new(new BundlerCtx(testData, output, "cm-"));
        bundler.Mangle          = true;
        bundler.CompressOptions = CompressOptions.Default;
        bundler.OutputOptions   = new() { Beautify = false };
        InitCommonParts(testData);
        bundler.Run();

        bundler                 = new(new BundlerCtx(testData, output, "cb-"));
        bundler.Mangle          = false;
        bundler.CompressOptions = CompressOptions.Default;
        bundler.OutputOptions   = new() { Beautify = true };
        InitCommonParts(testData);
        bundler.Run();

        bundler                 = new(new BundlerCtx(testData, output, "b-"));
        bundler.Mangle          = false;
        bundler.CompressOptions = null;
        bundler.OutputOptions   = new() { Beautify = true };
        InitCommonParts(testData);
        bundler.Run();

        return(output);

        void InitCommonParts(BundlerTestData testData)
        {
            var libraryMode = testData.Name.StartsWith("Library");

            bundler.LibraryMode        = libraryMode;
            bundler.PartToMainFilesMap =
                new Dictionary <string, IReadOnlyList <string> > {
                { "bundle", new[] { "index.js" } }
            };
            bundler.GlobalDefines = new Dictionary <string, object> {
                { "DEBUG", false }
            };
            if (libraryMode)
            {
                bundler.OutputOptions.Ecma = 10;
            }
        }
    }

    public class BundlerCtx : IBundlerCtx
    {
Пример #3
0
 public BundlerCtx(BundlerTestData testData, Dictionary <string, string> output, string outputPrefix)
 {
     _testData     = testData;
     _output       = output;
     _outputPrefix = outputPrefix;
 }