Convert tests to TypeScript

master
Anton Smirnov 2 months ago
parent 2d92d1ec16
commit beea262e6f
  1. 3
      .mocharc.js
  2. 1
      .npmignore
  3. 6
      package.json
  4. 51
      tests/spec/aliases.spec.ts
  5. 55
      tests/spec/angles.spec.ts
  6. 37
      tests/spec/frac.spec.ts
  7. 18
      tests/spec/hue.spec.ts
  8. 15
      tests/spec/node-sass.spec.ts
  9. 2
      tsconfig.json

@ -2,6 +2,7 @@
module.exports = {
spec: [
"tests/spec/**/*.js"
"tests/spec/**/*.spec.ts"
],
"require": "ts-node/register",
}

@ -9,3 +9,4 @@
/tests
/.mocharc.js
/.gitlab-ci.yml
/tsconfig.json

@ -24,9 +24,13 @@
"test": "mocha"
},
"devDependencies": {
"@types/chai": "^4.3.1",
"@types/mocha": "^9.1.1",
"@types/node-sass": "^4.11.2",
"chai": "^4.3.4",
"mocha": "^9.1.1",
"node-sass": "*",
"sass": "*"
"sass": "*",
"ts-node": "^10.8.1"
}
}

@ -1,72 +1,51 @@
'use strict';
import { assert } from 'chai';
import { compile } from 'sass';
import { readFileSync } from 'fs';
import { Options } from 'sass/types/options';
const chai = require('chai');
const assert = chai.assert;
const expected = readFileSync(__dirname + '/sass/aliases/expected.css').toString().trim();
const expectedAlpha = readFileSync(__dirname + '/sass/aliases/expected-alpha.css').toString().trim();
const sass = require('sass');
const fs = require('fs');
const expected = fs.readFileSync(__dirname + '/sass/aliases/expected.css').toString().trim();
const expectedAlpha = fs.readFileSync(__dirname + '/sass/aliases/expected-alpha.css').toString().trim();
const options: Options<'sync'> = {
style: 'compressed',
}
describe('hsv()', function () {
it('works', function () {
const actual = sass.renderSync({
file: __dirname + '/sass/aliases/hsv-test.scss',
outputStyle: 'compressed',
}).css.toString().trim();
const actual = compile(__dirname + '/sass/aliases/hsv-test.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
});
describe('hsb()', function () {
it('works', function () {
const actual = sass.renderSync({
file: __dirname + '/sass/aliases/hsb.scss',
outputStyle: 'compressed',
}).css.toString().trim();
const actual = compile(__dirname + '/sass/aliases/hsb.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
});
describe('hsva()', function () {
it('works', function () {
const actual = sass.renderSync({
file: __dirname + '/sass/aliases/hsva.scss',
outputStyle: 'compressed',
}).css.toString().trim();
const actual = compile(__dirname + '/sass/aliases/hsva.scss', options).css.toString().trim();
assert.equal(actual, expectedAlpha);
});
it('requires alpha param', function () {
assert.throws(function () {
sass.renderSync({
file: __dirname + '/sass/aliases/hsva-error.scss',
outputStyle: 'compressed',
});
compile(__dirname + '/sass/aliases/hsva-error.scss', options);
});
});
});
describe('hsba()', function () {
it('works', function () {
const actual = sass.renderSync({
file: __dirname + '/sass/aliases/hsba.scss',
outputStyle: 'compressed',
}).css.toString().trim();
const actual = compile(__dirname + '/sass/aliases/hsba.scss', options).css.toString().trim();
assert.equal(actual, expectedAlpha);
});
it('requires alpha param', function () {
assert.throws(function () {
sass.renderSync({
file: __dirname + '/sass/aliases/hsba-error.scss',
outputStyle: 'compressed',
});
compile(__dirname + '/sass/aliases/hsba-error.scss', options);
});
});
});

@ -1,74 +1,49 @@
'use strict';
import { assert } from 'chai';
import { compile } from 'sass';
import { readFileSync } from 'fs';
import { Options } from 'sass/types/options';
const chai = require('chai');
const assert = chai.assert;
const expected = readFileSync(__dirname + '/sass/angles/expected.css').toString().trim();
const sass = require('sass');
const fs = require('fs');
const expected = fs.readFileSync(__dirname + '/sass/angles/expected.css').toString().trim();
const options: Options<'sync'> = {
style: 'compressed',
}
describe('angle units', function () {
it('accepts unitless as degrees', function () {
const actual = sass.renderSync({
file: __dirname + '/sass/angles/unitless.scss',
outputStyle: 'compressed',
}).css.toString().trim();
const actual = compile(__dirname + '/sass/angles/unitless.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('accepts degrees', function () {
const actual = sass.renderSync({
file: __dirname + '/sass/angles/deg.scss',
outputStyle: 'compressed',
}).css.toString().trim();
const actual = compile(__dirname + '/sass/angles/deg.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('accepts radians', function () {
const actual = sass.renderSync({
file: __dirname + '/sass/angles/rad.scss',
outputStyle: 'compressed',
}).css.toString().trim();
const actual = compile(__dirname + '/sass/angles/rad.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('accepts turns', function () {
const actual = sass.renderSync({
file: __dirname + '/sass/angles/turn.scss',
outputStyle: 'compressed',
}).css.toString().trim();
const actual = compile(__dirname + '/sass/angles/turn.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('accepts grads', function () {
const actual = sass.renderSync({
file: __dirname + '/sass/angles/grad.scss',
outputStyle: 'compressed',
}).css.toString().trim();
const actual = compile(__dirname + '/sass/angles/grad.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('does not allow incompatible units: %', function () {
assert.throws(function () {
sass.renderSync({
file: __dirname + '/sass/angles/percent.scss',
outputStyle: 'compressed',
});
compile(__dirname + '/sass/angles/percent.scss', options);
});
});
it('does not allow incompatible units: pt', function () {
assert.throws(function () {
sass.renderSync({
file: __dirname + '/sass/angles/pt.scss',
outputStyle: 'compressed',
});
compile(__dirname + '/sass/angles/pt.scss', options);
});
});
});

@ -1,47 +1,34 @@
'use strict';
import { assert } from 'chai';
import { compile } from 'sass';
import { readFileSync } from 'fs';
import { Options } from 'sass/types/options';
const chai = require('chai');
const assert = chai.assert;
const expected = readFileSync(__dirname + '/sass/frac/expected.css').toString().trim();
const sass = require('sass');
const fs = require('fs');
const expected = fs.readFileSync(__dirname + '/sass/frac/expected.css').toString().trim();
const options: Options<'sync'> = {
style: 'compressed',
}
describe('fraction units', function () {
it('accepts unitless as fractions', function () {
const actual = sass.renderSync({
file: __dirname + '/sass/frac/fraction.scss',
outputStyle: 'compressed',
}).css.toString().trim();
const actual = compile(__dirname + '/sass/frac/fraction.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('accepts percent', function () {
const actual = sass.renderSync({
file: __dirname + '/sass/frac/percent.scss',
outputStyle: 'compressed',
}).css.toString().trim();
const actual = compile(__dirname + '/sass/frac/percent.scss', options).css.toString().trim();
assert.equal(actual, expected);
});
it('does not allow incompatible units: deg', function () {
assert.throws(function () {
sass.renderSync({
file: __dirname + '/sass/frac/deg.scss',
outputStyle: 'compressed',
});
compile(__dirname + '/sass/frac/deg.scss', options);
});
});
it('does not allow incompatible units: pt', function () {
assert.throws(function () {
sass.renderSync({
file: __dirname + '/sass/frac/pt.scss',
outputStyle: 'compressed',
});
compile(__dirname + '/sass/frac/pt.scss', options);
});
});
});

@ -1,19 +1,13 @@
'use strict';
const chai = require('chai');
const assert = chai.assert;
const sass = require('sass');
const fs = require('fs');
import { assert } from 'chai';
import { compile } from 'sass';
import { readFileSync } from 'fs';
describe('check all hue values with 10 degree step to verify all h1 branches', function () {
it('is valid', function () {
const actual = sass.renderSync({
file: __dirname + '/sass/hue/all-degrees.scss',
outputStyle: 'expanded',
const actual = compile(__dirname + '/sass/hue/all-degrees.scss', {
style: 'expanded',
}).css.toString().trim();
const expected = fs.readFileSync(__dirname + '/sass/hue/expected.css').toString().trim();
const expected = readFileSync(__dirname + '/sass/hue/expected.css').toString().trim();
assert.equal(actual, expected);
});

@ -1,19 +1,14 @@
'use strict';
const chai = require('chai');
const assert = chai.assert;
import { assert } from 'chai';
import { renderSync } from 'node-sass';
import { readFileSync } from 'fs';
describe('legacy libsass support' , function () {
it('works with node-sass', function () {
const sass = require('node-sass');
const fs = require('fs');
const actual = sass.renderSync({
const actual = renderSync({
file: __dirname + '/sass/node-sass/node-sass.scss',
outputStyle: 'compressed',
}).css;
const expected = fs.readFileSync(__dirname + '/sass/node-sass/expected.css');
const expected = readFileSync(__dirname + '/sass/node-sass/expected.css');
assert.equal(actual.toString(), expected.toString());
});

@ -0,0 +1,2 @@
{
}
Loading…
Cancel
Save