diff --git a/__tests__/__snapshots__/comment.js.snap b/__tests__/__snapshots__/comment.js.snap new file mode 100644 index 0000000..8f97288 --- /dev/null +++ b/__tests__/__snapshots__/comment.js.snap @@ -0,0 +1,275 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Comment should tokenize a comment that does not have a space before the end 1`] = ` +Array [ + Array [ + "startComment", + "/*", + 1, + 2, + ], + Array [ + "word", + "my", + 1, + 3, + 1, + 4, + ], + Array [ + "space", + " ", + ], + Array [ + "word", + "comment", + 1, + 6, + 1, + 12, + ], + Array [ + "endComment", + "*/", + 1, + 14, + ], +] +`; + +exports[`Comment should tokenize a docblock comment 1`] = ` +Array [ + Array [ + "startComment", + "/*", + 1, + 2, + ], + Array [ + "word", + "*", + 1, + 3, + 1, + 3, + ], + Array [ + "newline", + " +", + 2, + 0, + ], + Array [ + "space", + " ", + ], + Array [ + "word", + "*", + 2, + 2, + 2, + 2, + ], + Array [ + "space", + " ", + ], + Array [ + "word", + "line", + 2, + 4, + 2, + 7, + ], + Array [ + "space", + " ", + ], + Array [ + "word", + "1", + 2, + 9, + 2, + 9, + ], + Array [ + "newline", + " +", + 3, + 0, + ], + Array [ + "space", + " ", + ], + Array [ + "word", + "*", + 3, + 2, + 3, + 2, + ], + Array [ + "newline", + " +", + 4, + 0, + ], + Array [ + "space", + " ", + ], + Array [ + "word", + "*", + 4, + 2, + 4, + 2, + ], + Array [ + "space", + " ", + ], + Array [ + "word", + "line", + 4, + 4, + 4, + 7, + ], + Array [ + "space", + " ", + ], + Array [ + "word", + "2", + 4, + 9, + 4, + 9, + ], + Array [ + "newline", + " +", + 5, + 0, + ], + Array [ + "space", + " ", + ], + Array [ + "endComment", + "*/", + 5, + 3, + ], +] +`; + +exports[`Comment should tokenize a multiline comment 1`] = ` +Array [ + Array [ + "startComment", + "/*", + 1, + 2, + ], + Array [ + "newline", + " +", + 2, + 0, + ], + Array [ + "word", + "my", + 2, + 1, + 2, + 2, + ], + Array [ + "space", + " ", + ], + Array [ + "word", + "comment", + 2, + 4, + 2, + 10, + ], + Array [ + "newline", + " +", + 3, + 0, + ], + Array [ + "endComment", + "*/", + 3, + 2, + ], +] +`; + +exports[`Comment should tokenize a simple comment 1`] = ` +Array [ + Array [ + "startComment", + "/*", + 1, + 2, + ], + Array [ + "space", + " ", + ], + Array [ + "word", + "my", + 1, + 4, + 1, + 5, + ], + Array [ + "space", + " ", + ], + Array [ + "word", + "comment", + 1, + 7, + 1, + 13, + ], + Array [ + "space", + " ", + ], + Array [ + "endComment", + "*/", + 1, + 16, + ], +] +`; diff --git a/__tests__/__snapshots__/import.js.snap b/__tests__/__snapshots__/import.js.snap new file mode 100644 index 0000000..7710842 --- /dev/null +++ b/__tests__/__snapshots__/import.js.snap @@ -0,0 +1,327 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`@import should tokenize a @import with double quotes 1`] = ` +Array [ + Array [ + "@", + "@", + 1, + 1, + ], + Array [ + "ident", + "import", + 1, + 2, + 1, + 7, + ], + Array [ + "space", + " ", + ], + Array [ + "\\"", + "\\"", + 1, + 9, + ], + Array [ + "string", + "foo", + 1, + 10, + 1, + 12, + ], + Array [ + "\\"", + "\\"", + 1, + 13, + ], + Array [ + ";", + ";", + 1, + 14, + ], + Array [ + "newline", + " +", + 2, + 0, + ], +] +`; + +exports[`@import should tokenize a @import with double quotes and slash 1`] = ` +Array [ + Array [ + "@", + "@", + 1, + 1, + ], + Array [ + "ident", + "import", + 1, + 2, + 1, + 7, + ], + Array [ + "space", + " ", + ], + Array [ + "\\"", + "\\"", + 1, + 9, + ], + Array [ + "string", + "foo/bar", + 1, + 10, + 1, + 16, + ], + Array [ + "\\"", + "\\"", + 1, + 17, + ], + Array [ + ";", + ";", + 1, + 18, + ], + Array [ + "newline", + " +", + 2, + 0, + ], +] +`; + +exports[`@import should tokenize a @import with single quotes 1`] = ` +Array [ + Array [ + "@", + "@", + 1, + 1, + ], + Array [ + "ident", + "import", + 1, + 2, + 1, + 7, + ], + Array [ + "space", + " ", + ], + Array [ + "'", + "'", + 1, + 9, + ], + Array [ + "string", + "foo", + 1, + 10, + 1, + 12, + ], + Array [ + "'", + "'", + 1, + 13, + ], + Array [ + ";", + ";", + 1, + 14, + ], + Array [ + "newline", + " +", + 2, + 0, + ], +] +`; + +exports[`@import should tokenize a @import with single quotes and slash 1`] = ` +Array [ + Array [ + "@", + "@", + 1, + 1, + ], + Array [ + "ident", + "import", + 1, + 2, + 1, + 7, + ], + Array [ + "space", + " ", + ], + Array [ + "'", + "'", + 1, + 9, + ], + Array [ + "string", + "foo/bar", + 1, + 10, + 1, + 16, + ], + Array [ + "'", + "'", + 1, + 17, + ], + Array [ + ";", + ";", + 1, + 18, + ], + Array [ + "newline", + " +", + 2, + 0, + ], +] +`; + +exports[`@import should tokenize a @import without quotes 1`] = ` +Array [ + Array [ + "@", + "@", + 1, + 1, + ], + Array [ + "ident", + "import", + 1, + 2, + 1, + 7, + ], + Array [ + "space", + " ", + ], + Array [ + "ident", + "foo", + 1, + 9, + 1, + 11, + ], + Array [ + ";", + ";", + 1, + 12, + ], + Array [ + "newline", + " +", + 2, + 0, + ], +] +`; + +exports[`@import should tokenize a @import without quotes and slash 1`] = ` +Array [ + Array [ + "@", + "@", + 1, + 1, + ], + Array [ + "ident", + "import", + 1, + 2, + 1, + 7, + ], + Array [ + "space", + " ", + ], + Array [ + "ident", + "foo", + 1, + 9, + 1, + 11, + ], + Array [ + "/", + "/", + 1, + 12, + ], + Array [ + "ident", + "bar", + 1, + 13, + 1, + 15, + ], + Array [ + ";", + ";", + 1, + 16, + ], + Array [ + "newline", + " +", + 2, + 0, + ], +] +`; diff --git a/__tests__/comment.js b/__tests__/comment.js new file mode 100644 index 0000000..e132542 --- /dev/null +++ b/__tests__/comment.js @@ -0,0 +1,31 @@ +var scss = require('..'); +var fs = require('fs'); +var path = require('path'); + +var fixture = function(name) { + return fs.readFileSync( + path.join(__dirname, 'fixture', name) + ); +} + +describe('Comment', function() { + it('should tokenize a simple comment', function() { + const tree = scss.tokenize(fixture('simple-comment.scss')); + expect(tree).toMatchSnapshot(); + }); + + it('should tokenize a multiline comment', function() { + const tree = scss.tokenize(fixture('multiline-comment.scss')); + expect(tree).toMatchSnapshot(); + }); + + it('should tokenize a docblock comment', function() { + const tree = scss.tokenize(fixture('docblock-comment.scss')); + expect(tree).toMatchSnapshot(); + }); + + it('should tokenize a comment that does not have a space before the end', function() { + const tree = scss.tokenize(fixture('comment-with-trailing-space.scss')); + expect(tree).toMatchSnapshot(); + }); +}); diff --git a/test/fixture/comment-with-trailing-space.scss b/__tests__/fixture/comment-with-trailing-space.scss similarity index 100% rename from test/fixture/comment-with-trailing-space.scss rename to __tests__/fixture/comment-with-trailing-space.scss diff --git a/test/fixture/docblock-comment.scss b/__tests__/fixture/docblock-comment.scss similarity index 100% rename from test/fixture/docblock-comment.scss rename to __tests__/fixture/docblock-comment.scss diff --git a/test/fixture/double-quoted-import-path.scss b/__tests__/fixture/double-quoted-import-path.scss similarity index 100% rename from test/fixture/double-quoted-import-path.scss rename to __tests__/fixture/double-quoted-import-path.scss diff --git a/test/fixture/double-quoted-import.scss b/__tests__/fixture/double-quoted-import.scss similarity index 100% rename from test/fixture/double-quoted-import.scss rename to __tests__/fixture/double-quoted-import.scss diff --git a/test/fixture/multiline-comment.scss b/__tests__/fixture/multiline-comment.scss similarity index 100% rename from test/fixture/multiline-comment.scss rename to __tests__/fixture/multiline-comment.scss diff --git a/test/fixture/simple-comment.scss b/__tests__/fixture/simple-comment.scss similarity index 100% rename from test/fixture/simple-comment.scss rename to __tests__/fixture/simple-comment.scss diff --git a/test/fixture/single-quoted-import-path.scss b/__tests__/fixture/single-quoted-import-path.scss similarity index 100% rename from test/fixture/single-quoted-import-path.scss rename to __tests__/fixture/single-quoted-import-path.scss diff --git a/test/fixture/single-quoted-import.scss b/__tests__/fixture/single-quoted-import.scss similarity index 100% rename from test/fixture/single-quoted-import.scss rename to __tests__/fixture/single-quoted-import.scss diff --git a/test/fixture/unquoted-import-path.scss b/__tests__/fixture/unquoted-import-path.scss similarity index 100% rename from test/fixture/unquoted-import-path.scss rename to __tests__/fixture/unquoted-import-path.scss diff --git a/test/fixture/unquoted-import.scss b/__tests__/fixture/unquoted-import.scss similarity index 100% rename from test/fixture/unquoted-import.scss rename to __tests__/fixture/unquoted-import.scss diff --git a/__tests__/import.js b/__tests__/import.js new file mode 100644 index 0000000..3ab043e --- /dev/null +++ b/__tests__/import.js @@ -0,0 +1,41 @@ +var scss = require('..'); +var fs = require('fs'); +var path = require('path'); + +var fixture = function(name) { + return fs.readFileSync( + path.join(__dirname, 'fixture', name) + ); +} + +describe('@import', function() { + it('should tokenize a @import with double quotes', function() { + const tree = scss.tokenize(fixture('double-quoted-import.scss')); + expect(tree).toMatchSnapshot(); + }); + + it('should tokenize a @import with single quotes', function() { + const tree = scss.tokenize(fixture('single-quoted-import.scss')); + expect(tree).toMatchSnapshot(); + }); + + it('should tokenize a @import without quotes', function() { + const tree = scss.tokenize(fixture('unquoted-import.scss')); + expect(tree).toMatchSnapshot(); + }); + + it('should tokenize a @import with double quotes and slash', function() { + const tree = scss.tokenize(fixture('double-quoted-import-path.scss')); + expect(tree).toMatchSnapshot(); + }); + + it('should tokenize a @import with single quotes and slash', function() { + const tree = scss.tokenize(fixture('single-quoted-import-path.scss')); + expect(tree).toMatchSnapshot(); + }); + + it('should tokenize a @import without quotes and slash', function() { + const tree = scss.tokenize(fixture('unquoted-import-path.scss')); + expect(tree).toMatchSnapshot(); + }); +}); diff --git a/test/sass-spec.js b/__tests__/sass-spec.js similarity index 98% rename from test/sass-spec.js rename to __tests__/sass-spec.js index 701bc04..964f699 100644 --- a/test/sass-spec.js +++ b/__tests__/sass-spec.js @@ -32,5 +32,5 @@ describe('Sass spec', function() { contents = fs.readFileSync(file, { encoding: 'utf8' }); scss.tokenize(contents); } - }).timeout(30000); + }, 30000); }); diff --git a/package.json b/package.json index 5c6c428..7b3485b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A tokenzier for Sass' SCSS syntax", "main": "index.js", "scripts": { - "test": "mocha", + "test": "jest", "clean": "rm lib/*", "build": "npm run clean; babel src/ --out-dir lib" }, @@ -35,10 +35,11 @@ }, "devDependencies": { "babel-cli": "^6.26.0", + "babel-core": "^6.26.0", + "babel-jest": "^22.4.3", "babel-preset-es2015": "^6.24.1", - "chai": "^4.1.2", "glob": "^7.1.2", - "mocha": "^5.0.1", + "jest": "^22.4.3", "sass-spec": "^3.5.1" } } diff --git a/test/comment.js b/test/comment.js deleted file mode 100644 index 02ce6e8..0000000 --- a/test/comment.js +++ /dev/null @@ -1,85 +0,0 @@ -var scss = require('..'); -var fs = require('fs'); -var path = require('path'); -var assert = require('chai').assert; - -var fixture = function(name) { - return fs.readFileSync( - path.join(__dirname, 'fixture', name) - ); -} - -describe('Comment', function() { - it('should tokenize a simple comment', function() { - assert.deepEqual( - [ - ['startComment', '/*', 1, 2], - ['space', ' '], - ['word', 'my', 1, 4, 1, 5], - ['space', ' '], - ['word', 'comment', 1, 7, 1, 13], - ['space', ' '], - ['endComment', '*/', 1, 16], - ], - scss.tokenize(fixture('simple-comment.scss')) - ); - }); - - it('should tokenize a multiline comment', function() { - assert.deepEqual( - [ - ['startComment', '/*', 1, 2], - ['newline', '\n', 2, 0], - ['word', 'my', 2, 1, 2, 2], - ['space', ' '], - ['word', 'comment', 2, 4, 2, 10], - ['newline', '\n', 3, 0], - ['endComment', '*/', 3, 2], - ], - scss.tokenize(fixture('multiline-comment.scss')) - ); - }); - - it('should tokenize a docblock comment', function() { - assert.deepEqual( - [ - ['startComment', '/*', 1, 2], - ['word', '*', 1, 3, 1, 3], - ['newline', '\n', 2, 0], - ['space', ' '], - ['word', '*', 2, 2, 2, 2], - ['space', ' '], - ['word', 'line', 2, 4, 2, 7], - ['space', ' '], - ['word', '1', 2, 9, 2, 9], - ['newline', '\n', 3, 0], - ['space', ' '], - ['word', '*', 3, 2, 3, 2], - ['newline', '\n', 4, 0], - ['space', ' '], - ['word', '*', 4, 2, 4, 2], - ['space', ' '], - ['word', 'line', 4, 4, 4, 7], - ['space', ' '], - ['word', '2', 4, 9, 4, 9], - ['newline', '\n', 5, 0], - ['space', ' '], - ['endComment', '*/', 5, 3], - ], - scss.tokenize(fixture('docblock-comment.scss')) - ); - }); - - it('should tokenize a comment that does not have a space before the end', function() { - assert.deepEqual( - [ - ['startComment', '/*', 1, 2], - ['word', 'my', 1, 3, 1, 4], - ['space', ' '], - ['word', 'comment', 1, 6, 1, 12], - ['endComment', '*/', 1, 14], - ], - scss.tokenize(fixture('comment-with-trailing-space.scss')) - ); - }); -}); diff --git a/test/import.js b/test/import.js deleted file mode 100644 index 636660a..0000000 --- a/test/import.js +++ /dev/null @@ -1,106 +0,0 @@ -var scss = require('..'); -var fs = require('fs'); -var path = require('path'); -var assert = require('chai').assert; - -var fixture = function(name) { - return fs.readFileSync( - path.join(__dirname, 'fixture', name) - ); -} - -describe('@import', function() { - it('should tokenize a @import with double quotes', function() { - assert.deepEqual( - [ - ['@', '@', 1, 1], - ['ident', 'import', 1, 2, 1, 7], - ['space', ' '], - ['"', '"', 1, 9], - ['string', 'foo', 1, 10, 1, 12], - ['"', '"', 1, 13], - [';', ';', 1, 14], - ['newline', '\n', 2, 0], - ], - scss.tokenize(fixture('double-quoted-import.scss')) - ); - }); - - it('should tokenize a @import with single quotes', function() { - assert.deepEqual( - [ - ['@', '@', 1, 1], - ['ident', 'import', 1, 2, 1, 7], - ['space', ' '], - ['\'', '\'', 1, 9], - ['string', 'foo', 1, 10, 1, 12], - ['\'', '\'', 1, 13], - [';', ';', 1, 14], - ['newline', '\n', 2, 0], - ], - scss.tokenize(fixture('single-quoted-import.scss')) - ); - }); - - it('should tokenize a @import without quotes', function() { - assert.deepEqual( - [ - ['@', '@', 1, 1], - ['ident', 'import', 1, 2, 1, 7], - ['space', ' '], - ['ident', 'foo', 1, 9, 1, 11], - [';', ';', 1, 12], - ['newline', '\n', 2, 0], - ], - scss.tokenize(fixture('unquoted-import.scss')) - ); - }); - - it('should tokenize a @import with double quotes and slash', function() { - assert.deepEqual( - [ - ['@', '@', 1, 1], - ['ident', 'import', 1, 2, 1, 7], - ['space', ' '], - ['"', '"', 1, 9], - ['string', 'foo/bar', 1, 10, 1, 16], - ['"', '"', 1, 17], - [';', ';', 1, 18], - ['newline', '\n', 2, 0], - ], - scss.tokenize(fixture('double-quoted-import-path.scss')) - ); - }); - - it('should tokenize a @import with single quotes and slash', function() { - assert.deepEqual( - [ - ['@', '@', 1, 1], - ['ident', 'import', 1, 2, 1, 7], - ['space', ' '], - ['\'', '\'', 1, 9], - ['string', 'foo/bar', 1, 10, 1, 16], - ['\'', '\'', 1, 17], - [';', ';', 1, 18], - ['newline', '\n', 2, 0], - ], - scss.tokenize(fixture('single-quoted-import-path.scss')) - ); - }); - - it('should tokenize a @import without quotes and slash', function() { - assert.deepEqual( - [ - ['@', '@', 1, 1], - ['ident', 'import', 1, 2, 1, 7], - ['space', ' '], - ['ident', 'foo', 1, 9, 1, 11], - ['/', '/', 1, 12], - ['ident', 'bar', 1, 13, 1, 15], - [';', ';', 1, 16], - ['newline', '\n', 2, 0], - ], - scss.tokenize(fixture('unquoted-import-path.scss')) - ); - }); -});