Example #1
0
        describe("Relative to config file", () => {

            const relativePath = path.resolve("./foo/bar");

            overrideNativeResolve({
                "@foo/eslint-plugin-bar": getProjectModulePath("@foo/eslint-plugin-bar")
            });

            leche.withData([
                [".eslintrc", path.resolve("./foo/bar", ".eslintrc"), relativePath],
                ["eslint-config-foo", getRelativeModulePath("eslint-config-foo", relativePath), relativePath],
                ["foo", getRelativeModulePath("eslint-config-foo", relativePath), relativePath],
                ["eslint-configfoo", getRelativeModulePath("eslint-config-eslint-configfoo", relativePath), relativePath],
                ["@foo/eslint-config", getRelativeModulePath("@foo/eslint-config", relativePath), relativePath],
                ["@foo/bar", getRelativeModulePath("@foo/eslint-config-bar", relativePath), relativePath],
                ["plugin:@foo/bar/baz", getProjectModulePath("@foo/eslint-plugin-bar"), relativePath]
            ], (input, expected, relativeTo) => {
                it(`should return ${expected} when passed ${input}`, () => {

                    const configDeps = {
                        "eslint-config-foo": getRelativeModulePath("eslint-config-foo", relativePath),
                        "eslint-config-eslint-configfoo": getRelativeModulePath("eslint-config-eslint-configfoo", relativePath),
                        "@foo/eslint-config": getRelativeModulePath("@foo/eslint-config", relativePath),
                        "@foo/eslint-config-bar": getRelativeModulePath("@foo/eslint-config-bar", relativePath)
                    };

                    const StubbedConfigFile = proxyquire("../../../lib/config/config-file", {
                        "../util/module-resolver": createStubModuleResolver(configDeps)
                    });

                    const result = StubbedConfigFile.resolve(input, relativeTo);

                    assert.strictEqual(result.filePath, expected);
                });
            });

            leche.withData([
                ["eslint-config-foo/bar", path.resolve("./node_modules", "eslint-config-foo/bar", "index.json"), relativePath],
                ["eslint-config-foo/bar", path.resolve("./node_modules", "eslint-config-foo", "bar.json"), relativePath],
                ["eslint-config-foo/bar", path.resolve("./node_modules", "eslint-config-foo/bar", "index.js"), relativePath],
                ["eslint-config-foo/bar", path.resolve("./node_modules", "eslint-config-foo", "bar.js"), relativePath]
            ], (input, expected, relativeTo) => {
                it(`should return ${expected} when passed ${input}`, () => {

                    const configDeps = {
                        "eslint-config-foo/bar": expected
                    };

                    const StubbedConfigFile = proxyquire("../../../lib/config/config-file", {
                        "../util/module-resolver": createStubModuleResolver(configDeps)
                    });

                    const result = StubbedConfigFile.resolve(input, relativeTo);

                    assert.strictEqual(result.filePath, expected);
                });
            });

        });
Example #2
0
        describe("Relative to config file", function() {

            var relativePath = path.resolve("./foo/bar");

            leche.withData([
                [ ".eslintrc", path.resolve("./foo/bar", ".eslintrc"), relativePath ],
                [ "eslint-config-foo", getRelativeModulePath("eslint-config-foo", relativePath), relativePath],
                [ "foo", getRelativeModulePath("eslint-config-foo", relativePath), relativePath],
                [ "eslint-configfoo", getRelativeModulePath("eslint-config-eslint-configfoo", relativePath), relativePath],
                [ "@foo/eslint-config", getRelativeModulePath("@foo/eslint-config", relativePath), relativePath],
                [ "@foo/bar", getRelativeModulePath("@foo/eslint-config-bar", relativePath), relativePath],
                [ "plugin:@foo/bar/baz", getRelativeModulePath("@foo/eslint-plugin-bar", relativePath), relativePath]
            ], function(input, expected, relativeTo) {
                it("should return " + expected + " when passed " + input, function() {

                    var configDeps = {
                        "eslint-config-foo": getRelativeModulePath("eslint-config-foo", relativePath),
                        "eslint-config-eslint-configfoo": getRelativeModulePath("eslint-config-eslint-configfoo", relativePath),
                        "@foo/eslint-config": getRelativeModulePath("@foo/eslint-config", relativePath),
                        "@foo/eslint-config-bar": getRelativeModulePath("@foo/eslint-config-bar", relativePath),
                        "eslint-plugin-foo": getRelativeModulePath("eslint-plugin-foo", relativePath),
                        "@foo/eslint-plugin-bar": getRelativeModulePath("@foo/eslint-plugin-bar", relativePath)
                    };

                    var StubbedConfigFile = proxyquire("../../../lib/config/config-file", {
                        "../util/module-resolver": createStubModuleResolver(configDeps)
                    });

                    var result = StubbedConfigFile.resolve(input, relativeTo);

                    assert.equal(result.filePath, expected);
                });
            });

            leche.withData([
                [ "eslint-config-foo/bar", path.resolve("./node_modules", "eslint-config-foo/bar", "index.json"), relativePath],
                [ "eslint-config-foo/bar", path.resolve("./node_modules", "eslint-config-foo", "bar.json"), relativePath],
                [ "eslint-config-foo/bar", path.resolve("./node_modules", "eslint-config-foo/bar", "index.js"), relativePath],
                [ "eslint-config-foo/bar", path.resolve("./node_modules", "eslint-config-foo", "bar.js"), relativePath]
            ], function(input, expected, relativeTo) {
                it("should return " + expected + " when passed " + input, function() {

                    var configDeps = {
                        "eslint-config-foo/bar": expected
                    };

                    var StubbedConfigFile = proxyquire("../../../lib/config/config-file", {
                        "../util/module-resolver": createStubModuleResolver(configDeps)
                    });

                    var result = StubbedConfigFile.resolve(input, relativeTo);

                    assert.equal(result.filePath, expected);
                });
            });

        });
Example #3
0
describe("attachComment: true", function() {

    leche.withData(testFiles, function(filename) {
        it("should produce correct AST when parsed with attachComments", function() {
            var output = require(path.resolve(__dirname, "../../", filename + ".result.js"));
            var input = shelljs.cat(filename + ".src.js");
            var result;

            if (output.sourceType === "script") {
                result = espree.parse(input, {
                    loc: true,
                    range: true,
                    tokens: true,
                    attachComment: true
                });
            } else {
                result = espree.parse(input, {
                    loc: true,
                    range: true,
                    tokens: true,
                    attachComment: true,
                    sourceType: "module"
                });
            }

            assert.deepEqual(tester.getRaw(result), output);
        });

    });


});
Example #4
0
describe("Libraries", () => {

    leche.withData(testFiles, filename => {

        // var filename = "angular-1.2.5.js";

        it("should produce correct AST when parsed", function() {

            this.timeout(10000); // eslint-disable-line no-invalid-this

            const output = shelljs.cat(path.resolve(__dirname, "../../", `${filename}.result.json`));
            const input = shelljs.cat(filename);

            const result = JSON.stringify(tester.getRaw(espree.parse(input, {
                loc: true,
                range: true,
                tokens: true
            })));

            assert.strictEqual(result, output);
        });

    });


});
Example #5
0
        describe("Relative to CWD", function() {

            leche.withData([
                [ ".eslintrc", path.resolve(".eslintrc") ],
                [ "eslint-config-foo", getProjectModulePath("eslint-config-foo") ],
                [ "foo", getProjectModulePath("eslint-config-foo") ],
                [ "eslint-configfoo", getProjectModulePath("eslint-config-eslint-configfoo") ],
                [ "@foo/eslint-config", getProjectModulePath("@foo/eslint-config") ],
                [ "@foo/bar", getProjectModulePath("@foo/eslint-config-bar") ],
                [ "plugin:foo/bar", getProjectModulePath("eslint-plugin-foo") ]
            ], function(input, expected) {
                it("should return " + expected + " when passed " + input, function() {

                    var configDeps = {
                        "eslint-config-foo": getProjectModulePath("eslint-config-foo"),
                        "eslint-config-eslint-configfoo": getProjectModulePath("eslint-config-eslint-configfoo"),
                        "@foo/eslint-config": getProjectModulePath("@foo/eslint-config"),
                        "@foo/eslint-config-bar": getProjectModulePath("@foo/eslint-config-bar"),
                        "eslint-plugin-foo": getProjectModulePath("eslint-plugin-foo")
                    };

                    var StubbedConfigFile = proxyquire("../../../lib/config/config-file", {
                        "../util/module-resolver": createStubModuleResolver(configDeps)
                    });

                    var result = StubbedConfigFile.resolve(input);

                    assert.equal(result.filePath, expected);
                });
            });
        });
Example #6
0
        describe('with name option and', function () {
            withData({
                'nothing else': [{}],
                'checkAll option': [{checkAll: 'selection_all'}],
                'multiple option set to true': [{multiple: true}],
                'multiple and checkAll options, multiple set to false': [{multiple: false, checkAll: 'selection_all'}]
            }, function (customOptions) {
                it('should update data and do not activate "check all" functionality', function () {
                    $gridView = $('#w0').yiiGridView(settings);

                    var defaultOptions = {name: 'selection[]'};
                    var options = $.extend({}, defaultOptions, customOptions);
                    $gridView.yiiGridView('setSelectionColumn', options);

                    assert.equal($gridView.yiiGridView('data').selectionColumn, 'selection[]');

                    click($checkAllCheckbox);
                    assert.lengthOf($checkRowCheckboxes.filter(':checked'), 0);

                    click($checkAllCheckbox); // Back to initial condition
                    click($checkRowCheckboxes);
                    assert.isFalse($checkAllCheckbox.prop('checked'));
                });
            });
        });
Example #7
0
        describe("Relative to CWD", () => {
            overrideNativeResolve({
                "eslint-plugin-foo": getProjectModulePath("eslint-plugin-foo")
            });

            leche.withData([
                [".eslintrc", path.resolve(".eslintrc")],
                ["eslint-config-foo", getProjectModulePath("eslint-config-foo")],
                ["foo", getProjectModulePath("eslint-config-foo")],
                ["eslint-configfoo", getProjectModulePath("eslint-config-eslint-configfoo")],
                ["@foo/eslint-config", getProjectModulePath("@foo/eslint-config")],
                ["@foo/bar", getProjectModulePath("@foo/eslint-config-bar")],
                ["plugin:foo/bar", getProjectModulePath("eslint-plugin-foo")]
            ], (input, expected) => {
                it(`should return ${expected} when passed ${input}`, () => {

                    const configDeps = {
                        "eslint-config-foo": getProjectModulePath("eslint-config-foo"),
                        "eslint-config-eslint-configfoo": getProjectModulePath("eslint-config-eslint-configfoo"),
                        "@foo/eslint-config": getProjectModulePath("@foo/eslint-config"),
                        "@foo/eslint-config-bar": getProjectModulePath("@foo/eslint-config-bar"),
                        "eslint-plugin-foo": getProjectModulePath("eslint-plugin-foo")
                    };

                    const StubbedConfigFile = proxyquire("../../../lib/config/config-file", {
                        "../util/module-resolver": createStubModuleResolver(configDeps)
                    });

                    const result = StubbedConfigFile.resolve(input);

                    assert.strictEqual(result.filePath, expected);
                });
            });
        });
Example #8
0
    describe('refresh', function () {
        var server;
        var response = {hash1: 747, hash2: 748, url: '/site/captcha?v=584696959e038'};

        beforeEach(function () {
            server = sinon.fakeServer.create();
            window.XMLHttpRequest = global.XMLHttpRequest;
        });

        afterEach(function () {
            server.restore();
        });

        withData({
            'click on the captcha': [function () {
                $captcha.trigger('click');
            }],
            'manual method call': [function () {
                $captcha.yiiCaptcha('refresh');
            }]
        }, function (refreshFunction) {
            it('should send ajax request, update the image and data for client-side validation', function () {
                $captcha = $('#captcha').yiiCaptcha(settings);
                refreshFunction();
                server.requests[0].respond(200, {"Content-Type": "application/json"}, JSON.stringify(response));

                assert.lengthOf(server.requests, 1);
                assert.include(server.requests[0].url, settings.refreshUrl + '&_=');
                assert.include(server.requests[0].requestHeaders.Accept, 'application/json');
                assert.equal($captcha.attr('src'), response.url);
                assert.deepEqual($('body').data(settings.hashKey), [response.hash1, response.hash2]);
            });
        });
    });
Example #9
0
    describe("isSpaceBetweenTokens()", function() {

        leche.withData([
            ["let foo = bar;", true],
            ["let  foo = bar;", true],
            ["let /**/ foo = bar;", true],
            ["let/**/foo = bar;", false],
            ["a+b", false],
            ["a/**/+b", false],
            ["a/* */+b", false],
            ["a/**/ +b", true],
            ["a/**/ /**/+b", true],
            ["a/**/\n/**/+b", true],
            ["a +b", true]
        ], function(code, expected) {

            it("should return true when there is one space between tokens", function() {
                const ast = espree.parse(code, DEFAULT_CONFIG),
                    sourceCode = new SourceCode(code, ast);

                assert.equal(
                    sourceCode.isSpaceBetweenTokens(
                        sourceCode.ast.tokens[0], sourceCode.ast.tokens[1]
                    ),
                    expected
                );
            });
        });
    });
Example #10
0
    describe("write()", function() {

        var sandbox,
            config;

        beforeEach(function() {
            sandbox = sinon.sandbox.create();
            config = {
                env: {
                    browser: true,
                    node: true
                },
                rules: {
                    quotes: 2,
                    semi: 1
                }
            };
        });

        afterEach(function() {
            sandbox.verifyAndRestore();
        });

        leche.withData([
            ["JavaScript", "foo.js", readJSModule],
            ["JSON", "bar.json", JSON.parse],
            ["YAML", "foo.yaml", yaml.safeLoad],
            ["YML", "foo.yml", yaml.safeLoad]
        ], function(fileType, filename, validate) {

            it("should write a file through fs when a " + fileType + " path is passed", function() {
                var fakeFS = leche.fake(fs);

                sandbox.mock(fakeFS).expects("writeFileSync").withExactArgs(
                    filename,
                    sinon.match(function(value) {
                        return !!validate(value);
                    }),
                    "utf8"
                );

                var StubbedConfigFile = proxyquire("../../../lib/config/config-file", {
                    fs: fakeFS
                });

                StubbedConfigFile.write(config, filename);
            });

        });

        it("should throw error if file extension is not valid", function() {
            assert.throws(function() {
                ConfigFile.write({}, getFixturePath("yaml/.eslintrc.class"));
            }, /write to unknown file type/);
        });
    });
Example #11
0
        describe('with name, multiple and checkAll options, multiple set to true and', function () {
            withData({
                'nothing else': [{}],
                // https://github.com/yiisoft/yii2/pull/11729
                'class option': [{'class': 'w0-check-row'}]
            }, function (customOptions) {
                it('should update data and "check all" functionality should work', function () {
                    $gridView = $('#w0').yiiGridView(settings);

                    var defaultOptions = {name: 'selection[]', multiple: true, checkAll: 'selection_all'};
                    var options = $.extend({}, defaultOptions, customOptions);
                    $gridView.yiiGridView('setSelectionColumn', options);

                    assert.equal($gridView.yiiGridView('data').selectionColumn, 'selection[]');

                    var $checkFirstRowCheckbox = $checkRowCheckboxes.filter('[value="1"]');

                    // Check all
                    click($checkAllCheckbox);
                    assert.lengthOf($checkRowCheckboxes.filter(':checked'), 3);
                    assert.isTrue($checkAllCheckbox.prop('checked'));

                    // Uncheck all
                    click($checkAllCheckbox);
                    assert.lengthOf($checkRowCheckboxes.filter(':checked'), 0);
                    assert.isFalse($checkAllCheckbox.prop('checked'));

                    // Check all manually
                    click($checkRowCheckboxes);
                    assert.lengthOf($checkRowCheckboxes.filter(':checked'), 3);
                    assert.isTrue($checkAllCheckbox.prop('checked'));

                    // Uncheck all manually
                    click($checkRowCheckboxes);
                    assert.lengthOf($checkRowCheckboxes.filter(':checked'), 0);
                    assert.isFalse($checkAllCheckbox.prop('checked'));

                    // Check first row
                    click($checkFirstRowCheckbox);
                    assert.isTrue($checkFirstRowCheckbox.prop('checked'));
                    assert.lengthOf($checkRowCheckboxes.filter(':checked'), 1);
                    assert.isFalse($checkAllCheckbox.prop('checked'));

                    // Then check all
                    click($checkAllCheckbox);
                    assert.lengthOf($checkRowCheckboxes.filter(':checked'), 3);
                    assert.isTrue($checkAllCheckbox.prop('checked'));

                    // Uncheck first row
                    click($checkFirstRowCheckbox);
                    assert.isFalse($checkFirstRowCheckbox.prop('checked'));
                    assert.lengthOf($checkRowCheckboxes.filter(':checked'), 2);
                    assert.isFalse($checkAllCheckbox.prop('checked'));
                });
            });
        });
Example #12
0
    describe('init', function () {
        var customSettings = {
            filterUrl: '/posts/filter',
            filterSelector: '#w-common-filters input',
            filterOnFocusOut: true
        };

        withData({
            'no method specified': [function () {
                $gridView = $('.grid-view').yiiGridView(commonSettings);
            }, commonSettings],
            'no method specified, custom settings': [function () {
                $gridView = $('.grid-view').yiiGridView(customSettings);
            }, customSettings],
            'manual method call': [function () {
                $gridView = $('.grid-view').yiiGridView('init', commonSettings);
            }, commonSettings]
        }, function (initFunction, expectedSettings) {
            it('should save settings for all elements', function () {
                initFunction();
                assert.deepEqual($('#w0').yiiGridView('data'), {settings: expectedSettings});
                assert.deepEqual($('#w1').yiiGridView('data'), {settings: expectedSettings});
            });
        });

        describe('with repeated call', function () {
            var jQuerySubmitStub;

            before(function () {
                jQuerySubmitStub = sinon.stub($.fn, 'submit');
            });

            after(function () {
                jQuerySubmitStub.restore();
            });

            it('should remove "filter" event handler', function () {
                $gridView = $('#w0').yiiGridView(settings);
                $gridView.yiiGridView(settings);
                // Change selector to make sure event handlers are removed regardless of the selector
                $gridView.yiiGridView({
                    filterUrl: '/posts/index',
                    filterSelector: '#w0-filters select'
                });

                pressEnter($textInput);
                assert.isFalse(jQuerySubmitStub.called);

                changeValue($select, 1);
                assert.isTrue(jQuerySubmitStub.calledOnce);
            });
        });
    });
Example #13
0
    describe("getFilenameFromDirectory()", function() {

        leche.withData([
            [ getFixturePath("legacy"), ".eslintrc" ],
            [ getFixturePath("yaml"), ".eslintrc.yaml" ],
            [ getFixturePath("yml"), ".eslintrc.yml" ],
            [ getFixturePath("json"), ".eslintrc.json" ],
            [ getFixturePath("js"), ".eslintrc.js" ]
        ], function(input, expected) {
            it("should return " + expected + " when passed " + input, function() {
                var result = ConfigFile.getFilenameForDirectory(input);
                assert.equal(result, path.resolve(input, expected));
            });
        });

    });
Example #14
0
    describe("getFilenameFromDirectory()", () => {

        leche.withData([
            [getFixturePath("legacy"), ".eslintrc"],
            [getFixturePath("yaml"), ".eslintrc.yaml"],
            [getFixturePath("yml"), ".eslintrc.yml"],
            [getFixturePath("json"), ".eslintrc.json"],
            [getFixturePath("js"), ".eslintrc.js"]
        ], (input, expected) => {
            it(`should return ${expected} when passed ${input}`, () => {
                const result = ConfigFile.getFilenameForDirectory(input);

                assert.strictEqual(result, path.resolve(input, expected));
            });
        });

    });
Example #15
0
    describe("getShorthandName()", () => {

        leche.withData([
            ["foo", "foo"],
            ["eslint-config-foo", "foo"],
            ["@z", "@z"],
            ["@z/eslint-config", "@z"],
            ["@z/foo", "@z/foo"],
            ["@z/eslint-config-foo", "@z/foo"]
        ], (input, expected) => {
            it(`should return ${expected} when passed ${input}`, () => {
                const result = naming.getShorthandName(input, "eslint-config");

                assert.strictEqual(result, expected);
            });
        });

    });
Example #16
0
    describe("normalizePackageName()", function() {

        leche.withData([
            [ "foo", "eslint-config-foo" ],
            [ "eslint-config-foo", "eslint-config-foo" ],
            [ "@z/foo", "@z/eslint-config-foo" ],
            [ "@z\\foo", "@z/eslint-config-foo" ],
            [ "@z\\foo\\bar.js", "@z/eslint-config-foo/bar.js" ],
            [ "@z/eslint-config", "@z/eslint-config" ],
            [ "@z/eslint-config-foo", "@z/eslint-config-foo" ]
        ], function(input, expected) {
            it("should return " + expected + " when passed " + input, function() {
                var result = ConfigFile.normalizePackageName(input, "eslint-config");

                assert.equal(result, expected);
            });
        });

    });
Example #17
0
    describe("normalizePackageName()", () => {

        leche.withData([
            ["foo", "eslint-config-foo"],
            ["eslint-config-foo", "eslint-config-foo"],
            ["@z/foo", "@z/eslint-config-foo"],
            ["@z\\foo", "@z/eslint-config-foo"],
            ["@z\\foo\\bar.js", "@z/eslint-config-foo/bar.js"],
            ["@z/eslint-config", "@z/eslint-config"],
            ["@z/eslint-config-foo", "@z/eslint-config-foo"]
        ], (input, expected) => {
            it(`should return ${expected} when passed ${input}`, () => {
                const result = naming.normalizePackageName(input, "eslint-config");

                assert.strictEqual(result, expected);
            });
        });

    });
Example #18
0
    describe("Scripts", function() {

        leche.withData(scriptOnlyTestFiles, function(filename) {

            var version = filename.substring(0, filename.indexOf("/"));

            // Uncomment and fill in filename to focus on a single file
            // var filename = "newTarget/simple-new-target";
            var code = shelljs.cat(path.resolve(FIXTURES_DIR, filename) + ".src.js");

            it("should parse correctly when sourceType is script", function() {
                config.ecmaVersion = Number(version);
                var expected = require(path.resolve(__dirname, "../../", FIXTURES_DIR, filename) + ".result.js");

                tester.assertMatches(code, config, expected);
            });

        });

    });
Example #19
0
    describe("resolve()", function() {

        leche.withData([

            // resolve just like Node.js
            [ "leche", "", require.resolve("leche") ],

            // resolve with a different location
            [ "foo", path.resolve(FIXTURES_PATH, "node_modules"), path.resolve(FIXTURES_PATH, "node_modules/foo.js")]

        ], function(name, lookupPath, expected) {
            it("should find the correct location of a file", function() {
                let resolver = new ModuleResolver(),
                    result = resolver.resolve(name, lookupPath);

                assert.equal(result, expected);
            });
        });

    });
Example #20
0
        describe("Relative to CWD", function() {

            leche.withData([
                [ ".eslintrc", path.resolve(".eslintrc") ],
                [ "eslint-config-foo", getProjectModulePath("eslint-config-foo") ],
                [ "foo", getProjectModulePath("eslint-config-foo") ],
                [ "eslint-configfoo", getProjectModulePath("eslint-config-eslint-configfoo") ],
                [ "@foo/eslint-config", getProjectModulePath("@foo/eslint-config") ],
                [ "@foo/bar", getProjectModulePath("@foo/eslint-config-bar") ],
                [ "plugin:foo/bar", getProjectModulePath("eslint-plugin-foo") ]
            ], function(input, expected) {
                it("should return " + expected + " when passed " + input, function() {

                    // used to stub out resolve.sync
                    target = expected;

                    var result = StubbedConfigFile.resolve(input);
                    assert.equal(result.filePath, expected);
                });
            });
        });
Example #21
0
    describe("isError()", function() {

        leche.withData([
            ["error", true],
            ["Error", true],
            [2, true],
            [["error"], true],
            [["erRor"], true],
            [[2], true],
            [["error", "foo"], true],
            [["eRror", "bar"], true],
            [[2, "baz"], true]
        ], function(input, expected) {

            it("should return " + expected + "when passed " + input, function() {
                var result = ConfigOps.isErrorSeverity(input);
                assert.equal(result, expected);
            });

        });

    });
Example #22
0
    describe("Modules", function() {

        leche.withData(moduleTestFiles, function(filename) {

            var version = filename.substring(0, filename.indexOf("/"));
            var code = shelljs.cat(path.resolve(FIXTURES_DIR, filename) + ".src.js");

            it("should parse correctly when sourceType is module", function() {
                var expected = require(path.resolve(__dirname, "../../", FIXTURES_DIR, filename) + ".result.js");

                config.ecmaVersion = Number(version);
                config.sourceType = "module";

                // set sourceType of program node to module
                if (expected.type === "Program") {
                    expected.sourceType = "module";
                }

                tester.assertMatches(code, config, expected);
            });

        });
    });
Example #23
0
    describe("isError()", () => {

        leche.withData([
            ["error", true],
            ["Error", true],
            [2, true],
            [["error"], true],
            [["erRor"], true],
            [[2], true],
            [["error", "foo"], true],
            [["eRror", "bar"], true],
            [[2, "baz"], true]
        ], (input, expected) => {

            it(`should return ${expected}when passed ${input}`, () => {
                const result = ConfigOps.isErrorSeverity(input);

                assert.equal(result, expected);
            });

        });

    });
Example #24
0
    describe('init', function () {
        var customSettings = {
            refreshUrl: '/posts/captcha?refresh=1',
            hashKey: 'yiiCaptcha/posts/captcha'
        };

        withData({
            'no method specified': [function () {
                $captcha = $('.captcha').yiiCaptcha(settings);
            }, settings],
            'no method specified, custom options': [function () {
                $captcha = $('.captcha').yiiCaptcha(customSettings);
            }, customSettings],
            'manual method call': [function () {
                $captcha = $('.captcha').yiiCaptcha('init', settings);
            }, settings]
        }, function (initFunction, expectedSettings) {
            it('should save settings for all elements', function () {
                initFunction();
                assert.deepEqual($('#captcha').data('yiiCaptcha'), {settings: expectedSettings});
                assert.deepEqual($('#captcha-2').data('yiiCaptcha'), {settings: expectedSettings});
            });
        });
    });
describe('index client factory', function() {
  withData([
    ['apiGateway', 'APIGateway'],
    ['autoScaling', 'AutoScaling'],
    ['cloudFormation', 'CloudFormation'],
    ['cloudFront', 'CloudFront'],
    ['cloudWatch', 'CloudWatch'],
    ['cognitoIdentity', 'CognitoIdentity'],
    ['dynamoDb', 'DynamoDB'],
    ['ec2', 'EC2'],
    ['ecs', 'ECS'],
    ['elastiCache', 'ElastiCache'],
    ['elb', 'ELB'],
    ['es', 'ES'],
    ['iam', 'IAM'],
    ['iot', 'Iot'],
    ['iotData', 'IotData'],
    ['kinesis', 'Kinesis'],
    ['kms', 'KMS'],
    ['lambda', 'Lambda'],
    ['metadataService', 'MetadataService'],
    ['route53', 'Route53'],
    ['s3', 'S3'],
    ['ses', 'SES'],
    ['sns', 'SNS'],
    ['sqs', 'SQS']
  ], function(factoryMethod) {
    it(factoryMethod + ' is a function', function() {
      assert.equal(
        typeof clientFactory[factoryMethod],
        'function',
        'has factory method for client type'
      );
    });
  });
});
Example #26
0
        describe("Relative to config file", function() {

            var relativePath = path.resolve("./foo/bar");

            leche.withData([
                [ ".eslintrc", path.resolve("./foo/bar", ".eslintrc"), relativePath ],
                [ "eslint-config-foo", getRelativeModulePath("eslint-config-foo", relativePath), relativePath],
                [ "foo", getRelativeModulePath("eslint-config-foo", relativePath), relativePath],
                [ "eslint-configfoo", getRelativeModulePath("eslint-config-eslint-configfoo", relativePath), relativePath],
                [ "@foo/eslint-config", getRelativeModulePath("@foo/eslint-config", relativePath), relativePath],
                [ "@foo/bar", getRelativeModulePath("@foo/eslint-config-bar", relativePath), relativePath],
                [ "plugin:@foo/bar/baz", getRelativeModulePath("@foo/eslint-plugin-bar", relativePath), relativePath]
            ], function(input, expected, relativeTo) {
                it("should return " + expected + " when passed " + input, function() {

                    // used to stub out resolve.sync
                    target = expected;

                    var result = StubbedConfigFile.resolve(input, relativeTo);
                    assert.equal(result.filePath, expected);
                });
            });

        });
Example #27
0
 describe('getSelectedRows method', function () {
     withData({
         'selectionColumn not set, no rows selected': [undefined, [], false, []],
         'selectionColumn not set, 1st and 2nd rows selected': [undefined, [1, 2], false, []],
         'selectionColumn set, no rows selected': ['selection[]', [], false, []],
         'selectionColumn set, 1st row selected': ['selection[]', [1], false, [1]],
         'selectionColumn set, 1st and 2nd rows selected': ['selection[]', [1, 2], false, [1, 2]],
         'selectionColumn set, all rows selected, "Check all" checkbox checked': [
             'selection[]', [1, 2, 3], true, [1, 2, 3]
         ]
     }, function (selectionColumn, selectedRows, checkAll, expectedSelectedRows) {
         it('should return array with ids of selected rows', function () {
             $gridView = $('#w0').yiiGridView(settings);
             $gridView.yiiGridView('setSelectionColumn', {name: selectionColumn});
             for (var i = 0; i < selectedRows.length; i++) {
                 $checkRowCheckboxes.filter('[value="' + selectedRows[i] + '"]').prop('checked', true);
             }
             if (checkAll) {
                 $checkAllCheckbox.prop('checked', true);
             }
             assert.deepEqual($gridView.yiiGridView('getSelectedRows'), expectedSelectedRows);
         });
     });
 });
describe("ecmaFeatures", function() {

    var config;

    beforeEach(function() {
        config = {
            loc: true,
            range: true,
            tokens: true,
            ecmaFeatures: {}
        };
    });

    leche.withData(testFiles, function(filename) {
        // Uncomment and fill in filename to focus on a single file
        // var filename = "jsx/invalid-matching-placeholder-in-closing-tag";
        var feature = path.dirname(filename),
            code = shelljs.cat(path.resolve(FIXTURES_DIR, filename) + ".src.js");

        it("should parse correctly when " + feature + " is true", function() {
            config.ecmaFeatures[feature] = true;
            var expected = require(path.resolve(__dirname, "../../", FIXTURES_DIR, filename) + ".result.js");
            var result;

            try {
                result = parser.parse(code, config);
                result = getRaw(result);
            } catch (ex) {

                // format of error isn't exactly the same, just check if it's expected
                if (expected.message) {
                    return;
                } else {
                    throw ex;
                }

            }
            assert.deepEqual(result, expected);
        });

    });

    // describe("Modules", function() {

    //     leche.withData(moduleTestFiles, function(filename) {

    //         var code = shelljs.cat(path.resolve(FIXTURES_DIR, filename) + ".src.js");

    //         it("should parse correctly when sourceType is module", function() {
    //             var expected = require(path.resolve(__dirname, "../../", FIXTURES_DIR, filename) + ".result.js");
    //             var result;

    //             config.sourceType = "module";

    //             // set sourceType of program node to module
    //             if (expected.type === "Program") {
    //                 expected.sourceType = "module";
    //             }

    //             try {
    //                 result = getRaw(parser.parse(code, config));
    //             } catch (ex) {

    //                 // if the result is an error, create an error object so deepEqual works
    //                 if (expected.message || expected.description) {
    //                     result = getRaw(ex);
    //                     result.message = ex.message;
    //                 } else {
    //                     throw ex;
    //                 }

    //             }

    //             assert.deepEqual(result, expected);
    //         });

    //     });
    // });



    // leche.withData(mixFiles, function(filename) {

    //     var features = path.dirname(filename),
    //         code = shelljs.cat(path.resolve(FIXTURES_MIX_DIR, filename) + ".src.js");

    //     it("should parse correctly when " + features + " are true", function() {
    //         config.ecmaFeatures = require(path.resolve(__dirname, "../../", FIXTURES_MIX_DIR, filename) + ".config.js");

    //         var expected = require(path.resolve(__dirname, "../../", FIXTURES_MIX_DIR, filename) + ".result.js");
    //         var result;

    //         try {
    //             result = parser.parse(code, config);
    //             result = getRaw(result);
    //         } catch (ex) {

    //             // if the result is an error, create an error object so deepEqual works
    //             if (expected.message || expected.description) {
    //                 result = getRaw(ex);
    //                 result.message = ex.message;
    //             } else {
    //                 throw ex;
    //             }
    //         }

    //         assert.deepEqual(result, expected);
    //     });

    // });


});
                before(function(dynamicDataModelDeclSuiteDone_) {

                    var addressRoot = onmModel.createRootAddress();

                    var suiteA = Suite.create(dynamicDataModelDeclSuite, "Check onm model '" + onmModel.jsonTag + "' extension point configuration.");

                    if (onmModel.implementation.countExtensionPoints) {

                        var whiteBoxSemanticBindings = onmModel.implementation.objectModelDeclaration.semanticBindings;

                        suiteA.addTest(new Test("'" + onmModel.jsonTag + "' semantic binding should define the 'keyPropertyName' property.", function() {
                            assert.property(whiteBoxSemanticBindings, 'keyPropertyName');
                            assert.isString(whiteBoxSemanticBindings.keyPropertyName);
                        }));

                        suiteA.addTest(new Test("'" + onmModel.jsonTag + "' data model should declare a 'semanticBinding' sub-object.", function() {
                            assert.isDefined(whiteBoxSemanticBindings);
                            assert.isObject(whiteBoxSemanticBindings);
                        }));

                        suiteA.addTest(new Test("'" + onmModel.jsonTag + "' semantic binding should define key setter function.", function() {
                            assert.property(whiteBoxSemanticBindings, 'setUniqueKey');
                            assert.isFunction(whiteBoxSemanticBindings.setUniqueKey);
                        }));

                        suiteA.addTest(new Test("'" + onmModel.jsonTag + "' semantic binding should define a key getter function.", function() {
                            assert.property(whiteBoxSemanticBindings, 'getUniqueKey');
                            assert.isFunction(whiteBoxSemanticBindings.getUniqueKey);
                        }));

                        suiteA.addTest(new Test("'" + onmModel.jsonTag + "' key setter basic test.", function() {
                            var data = {};
                            var keyValue = whiteBoxSemanticBindings.setUniqueKey(data);
                            assert.property(data, whiteBoxSemanticBindings.keyPropertyName);
                            assert.isString(data[whiteBoxSemanticBindings.keyPropertyName]);
                            assert.isDefined(keyValue);
                            assert.isNotNull(keyValue);
                            assert.isString(keyValue);
                            assert.equal(keyValue, data[whiteBoxSemanticBindings.keyPropertyName]);
                        }));

                        suiteA.addTest(new Test("'" + onmModel.jsonTag + "' key setter override key value on set test.", function() {
                            var data = {};
                            var testKey = "testkey1";
                            var keyValue = whiteBoxSemanticBindings.setUniqueKey(data, testKey);
                            assert.property(data, whiteBoxSemanticBindings.keyPropertyName);
                            assert.isString(data[whiteBoxSemanticBindings.keyPropertyName]);
                            assert.equal(data[whiteBoxSemanticBindings.keyPropertyName], testKey);
                            assert.isDefined(keyValue);
                            assert.isNotNull(keyValue);
                            assert.isString(keyValue);
                            assert.equal(keyValue, testKey);
                        }));

                        suiteA.addTest(new Test("'" + onmModel.jsonTag + "' key getter test.", function() {
                            var testKey = "testkey2";
                            var data = {};
                            data[whiteBoxSemanticBindings.keyPropertyName] = testKey;
                            var keyActual = whiteBoxSemanticBindings.getUniqueKey(data);
                            assert.equal(keyActual, testKey);
                        }));

                        var suiteB = Suite.create(suiteA, "Check onm model '" + onmModel.jsonTag + "' component namespace key property declaration(s).");

                        var componentDescriptorTestSuites = {};


                        for (var index = 0 ; index < onmModel.implementation.countDescriptors ; index++) {
                            var objectModelDescriptor = onmModel.implementation.getNamespaceDescriptorFromPathId(index);
                            if (objectModelDescriptor.namespaceType === "component") {
                                var testName = "'" + onmModel.jsonTag + "' component namespace path '" + objectModelDescriptor.path + "' key property declaration test.";
                                componentDescriptorTestSuites[testName] = [ {
                                    testName: testName,
                                    objectModelDescriptor: objectModelDescriptor
                                } ];
                            }
                        }

                        withData(componentDescriptorTestSuites, function (testDescriptor_) {

                            var objectModelDescriptor = testDescriptor_.objectModelDescriptor;

                            describe("Verify '" + objectModelDescriptor.path + "' property declaration object.", function() {
                                it("Component namespace descriptor should define 'namespaceModelPropertiesDeclaration' property.", function() {
                                    assert.property(objectModelDescriptor, 'namespaceModelPropertiesDeclaration');
                                });
                                it("Component namespace descriptor property declaration should be an object.", function() {
                                    assert.isObject(objectModelDescriptor.namespaceModelPropertiesDeclaration);
                                });
                                it("Component namespace descriptor property declaration should define 'userImmutable'.", function() {
                                    assert.property(objectModelDescriptor.namespaceModelPropertiesDeclaration, 'userImmutable');
                                });
                                it("Component namespace descriptor immutable property declaration should be an object.", function() {
                                    assert.isObject(objectModelDescriptor.namespaceModelPropertiesDeclaration.userImmutable);
                                });
                                describe("Verify '" + objectModelDescriptor.path + "' component key declaration.", function() {
                                    it("Execute property declaration object verification tests.", function() { assert.isTrue(true); });
                                });
                            });
                        });

                    }

                    dynamicDataModelDeclSuiteDone_();

                });
Example #30
0
            describe('with no filter data sent', function () {
                withData({
                    // https://github.com/yiisoft/yii2/issues/13738
                    'question mark, no query parameters': [
                        '/posts/index?',
                        '/posts/index',
                        'PostSearch[name]=&PostSearch[category_id]='
                    ],
                    'query parameters': [
                        '/posts/index?foo=1&bar=2',
                        '/posts/index',
                        'PostSearch[name]=&PostSearch[category_id]=&foo=1&bar=2'
                    ],
                    // https://github.com/yiisoft/yii2/pull/10302
                    'query parameter with multiple values (not array)': [
                        '/posts/index?foo=1&foo=2',
                        '/posts/index',
                        'PostSearch[name]=&PostSearch[category_id]=&foo=1&foo=2'
                    ],
                    'query parameter with multiple values (array)': [
                        '/posts/index?foo[]=1&foo[]=2',
                        '/posts/index',
                        'PostSearch[name]=&PostSearch[category_id]=&foo[]=1&foo[]=2'
                    ],
                    // https://github.com/yiisoft/yii2/issues/12836
                    'anchor': [
                        '/posts/index#post',
                        '/posts/index#post',
                        'PostSearch[name]=&PostSearch[category_id]='
                    ],
                    'query parameters, anchor': [
                        '/posts/index?foo=1&bar=2#post',
                        '/posts/index#post',
                        'PostSearch[name]=&PostSearch[category_id]=&foo=1&bar=2'
                    ],
                    'relative url, query parameters': [
                        '?foo=1&bar=2',
                        '',
                        'PostSearch[name]=&PostSearch[category_id]=&foo=1&bar=2'
                    ],
                    'relative url, anchor': [
                        '#post',
                        '#post',
                        'PostSearch[name]=&PostSearch[category_id]='
                    ],
                    'relative url, query parameters, anchor': [
                        '?foo=1&bar=2#post',
                        '#post',
                        'PostSearch[name]=&PostSearch[category_id]=&foo=1&bar=2'
                    ]
                }, function (filterUrl, expectedUrl, expectedQueryString) {
                    it('should send the request to correct url with correct parameters', function () {
                        var customSettings = $.extend({}, settings, {filterUrl: filterUrl});
                        $gridView = $('#w0').yiiGridView(customSettings);
                        $gridView.yiiGridView('applyFilter');

                        var $form = $gridView.find('.gridview-filter-form');
                        assert.isTrue(jQuerySubmitStub.calledOnce);
                        assert.equal($form.attr('action'), expectedUrl);
                        assert.equal(decodeURIComponent($form.serialize()), expectedQueryString);
                    });
                });
            });