2.1.15 • Published 4 days ago

@kollorg/illum-corrupti-sapiente v2.1.15

Weekly downloads
-
License
MIT
Repository
github
Last release
4 days ago

Coverage Status

Sassy Test

Sassy Test is a simple helper utility for creating unit tests of Sass modules.

Sassy Test models its testing after the unit tests in LibSass. The tests are a series of sub-folders in the "test/fixtures" directory that contain an "input" Sass file and an "output" CSS file. Its unit tests then reference a particular folder, compile the input.scss and compare the results to the output.css file.

To get started, just install Sassy Test as a development dependency of your Sass module with: npm install --save-dev @kollorg/illum-corrupti-sapiente

Sassy Test will work with any Node.js test runner, like mocha or jasmine.

A quick demo of Mocha + Sassy Test

Example project's root directory:

|   # You can put your module's Sass files anywhere.
|   # We use "sass" as an example.
├─┬ sass/
│ └── _mymodule.scss
│   # Mocha prefers your tests to live in a "test" folder.
│   # Sassy Test will automatically find your fixtures if
│   # they are in /test/fixtures, but you can change the
│   # path with configurePaths().
└─┬ test/
  ├─┬ fixtures/
  │ │   # Test fixtures can be deeply nested.
  │ ├─┬ my-modules-function/
  │ │ ├── input.scss
  │ │ └── output.css
  │ ├─┬ my-modules-error/
  │ │ ├── input.scss
  │ │ └── output.css
  │ └─┬ my-modules-warn/
  │   ├── input.scss
  │   └── output.css
  └── test_mymodule.scss

Then in our test file, test/test_mymodule.js, we can use sassyTest to simplify our tests:

import path from 'node:path';
import { expect } from 'chai';
import SassyTest from '@kollorg/illum-corrupti-sapiente';

const sassyTest = new SassyTest({
  // Path to the Sass module we are testing and its dependencies.
  loadPaths: [
    path.join(__dirname, '../sass'),
    path.join(__dirname, '../node_modules/breakpoint-sass/stylesheets')
  ]
  // Since our fixtures are in test/fixtures, we don't need to override
  // the default value by setting the "fixtures" path here.
  // fixtures: path.join(__dirname, 'fixtures'),
});

describe('@import "mymodule";', function() {
  describe('@function my-modules-function()', function() {
    it('should test an aspect of this function', async function() {
      // Sassy Test's compileFixture() will run a comparison test between the
      // compiled input.scss and the output.css found in the fixtures
      // sub-directory specified in its first parameter, in this case:
      // test/fixtures/my-modules-function
      return sassyTest.compileFixture('my-modules-function')
        .catch(error => {
          // If we expect the comparison test to succeed, we just need to test
          // that no error occurred.
          expect(error).to.not.exist;
        })
        .then(result => {
          // No additional assertions are needed, but we can run other tests
          // here if we desire.
        });
    });

    it('should throw an error in this situation', async function() {
      // Sassy Test's compileFixture() can also test if your module produces an
      // intentional error with Sass' @error directive.
      return sassyTest.compileFixture('my-modules-error')
        .catch(error => {
          // If the Sass in test/fixtures/my-modules-error/input.scss triggers an
          // @error in your module, you should expect the error object to exist
          // and to contain the error message from your module.
          expect(error).to.exist;
          expect(error.message).to.equal('Some helpful error message from your module.');
        });
    });

    it('should warn in another situation', async function() {
      // Sassy Test's compileFixture() can also test if your module produces an
      // intentional warning message with Sass' @warn directive.
      return sassyTest.compileFixture('my-modules-warn')
        .catch(error => {
          // If the Sass in test/fixtures/my-modules-warn/input.scss triggers a
          // @warn in your module, you should expect the result object to exist
          // and to contain the warn message from your module.
          expect(error).to.not.exist;
        })
        .then(result => {
          // Sassy Test adds two new arrays to sass' result object:
          // result.warn and result.debug are arrays of strings.
          expect(result.warn[0]).to.equal('Some helpful warning from your module.');
        });
    });
  });
});

For more information about configuring a SassyTest object, see the configurePaths() method documentation.

JavaScript Promises

SassyTest's compile(), compileString() and compileFixture() methods return a Promise.

describe('@import "mymodule";', function() {
  describe('@function my-modules-function()', function() {
    it('should test an aspect of this function', function() {
      // Mocha accepts sassyTest's returned Promise.
      return sassyTest.compileFixture('my-modules-function');
    });

    it('should throw an error in this situation', function() {
      return sassyTest.compileFixture('my-modules-error').then(function(result) {
        // If the expected Sass error does not occur, we need to fail the test.
        expect(result).to.not.exist('An error should have occurred');
      }).catch(function(error) {
        expect(error).to.exist;
        expect(error.message).to.include('Some helpful error message from your module.');
      });
    });

    it('should warn in another situation', function() {
      return sassyTest.compileFixture('my-modules-warn').then(function(result) {
        expect(result.warn[0]).to.equal('Some helpful warning from your module.');
      });
    });
  });
});

Full documentation of Sassy Test’s JavaScript API is available online.

Development

Forking, hacking, and tearing apart of this software is welcome! It's still very simple and could use additional features and conveniences.

After you've cloned this repository, run npm install and then you'll be able to run the module's mocha and eslint tests with npm test.

Contributors

None but me yet. All are welcome! https://github.com/kollorg/illum-corrupti-sapiente/graphs/contributors

URLSearchParamsECMAScript 2023inferencecurlwatchingtc39ponyfilltimewordwraparraybuffertrimEndcorecallawesomesauceexpressionstringfullsnsgetOwnPropertyDescriptorkeysregularcryptowhichbyteutildropa11yratebrowserlistArray.prototype.flatMapcryptrobustcallbindowntrimLeftstablereact-hookschannelworkspace:*ECMAScript 2020css nestingsyntaxrangeerrorclassestrimhttpsetImmediateamazonlimitedCSSemitmixinsfilterxtermcheckcloudformationFunction.prototype.nameArrayBuffer.prototype.slicecollectionfromjsnegative zeroobjwriteES2019predictableserializationprotocol-buffersfsevents.envmodulesgetoptvaluescopybootstrap lesshasparsingmomentcodescachereducerkinesispatchMicrosoftArraywarninguninstallruntimeelmpushwalkingshrinkwraptermESqsES2023scheme-validationbyteOffsetshellbrowserrdsframeworkjasminefastclonetoolsURLvalidoptionschemaxhrinspectFloat64Arraypositiveeslintpluginnested cssjsxstylesheetless mixinsECMAScript 2022tddstreamsurldayjsredirectinternal slotrm -frvestBigInt64Arraylookformstslibflagfast-deep-cloneeverymobilezeroglaciercloudwatchfastfast-deep-copyhotpathisdynamodbqueuenativesidepolyfillES2015linkflagsmergeespreeprettyECMAScript 2017electronbusytypeerrorunicodeparentexecrfc4122dependency managerwatchFileentriesESnexttrimRightvariableslibphonenumbernameses8flattentoStringTagSymbolbluebirdArray.prototype.filterimportexporttostringtag@@toStringTagstarterstdlibparentsomitredux-toolkitpersistentPromisemetadataTypedArrayquerystringtypesjsonpathcolourbundlingargsmoduleObject.entriesextendUnderscorewebparseconsolekoreanstoragegatewayencryptionObject.keysformatstatelessstylinglanguagejestdependenciesendercjkgetintrinsichookformsafe256ieES2022deepReflect.getPrototypeOflistenershashreal-timestylecallbackconsumecoercibletypeofl10npnpm9ECMAScript 2019JSONTypeBoxtypedajaxratelimit0ES2020WebSocketsdescriptortestperformanceautoscalingArray.prototype.containsgradients css3ReactiveXdeep-copyinputresolveinstallerrandomelbebstypedarraysdateroute53package.jsonartstyled-componentstapconfigurableprototypeES2021BigUint64ArrayreactavaprivateargvpromisesStyleSheetclonecharacterfast-copydatastructurelivepackagesshebangpostcssredactglobvalidatemime-dbgroupBylesscssloadbalancingmatchreducecloudfrontRFC-6455formattingswffsapolloperformantreduxprotobufintrinsicextensionroutingeventEmitterECMAScript 7mochaES6phonecss lessendpointdeepcloneawaitfetchlesscolumnArrayBufferless csstypanionimportless.jslockfilecallboundeslint-pluginObservablemiddlewareES2018ES8getPrototypeOfCSSStyleDeclarationwalkes-shimsupvariables in cssdeterministicautoprefixerkarmarequiretapespinnerescaperegexcall-boundflatMapfindes2015characterssimpledbgradients csssymbolmapStreamslocationsortpackage managerbddlinewrapUint16ArraysharedarraybufferwritableInt8Arraylintio-tssequenceES2017shimwidthawsrm -rffpsrmcolorsrapidmruchairmdirlazybannerarktypedebuges6MapECMAScript 2021foldercreatefastcopyfindLastIndexrequestiterationwait_.extendgraphqlfixed-width-0call-bindtoSortedeslintconfignpmbreaksyntaxerrorES5estreeefficientcompilertakestreams2stringifierloadingECMAScript 2015getasciidescriptionerrortexttraverseloggeridairbnbfunctionopenlogjsdomtestingmoveObject.isArray.prototype.includesboundsymlinkthroatenumerablecircularoutpututilitiesRxJShardlinksObject.fromEntriesECMAScript 5Uint32ArrayequalastelasticachebcryptimmutableslotbufferArray.prototype.findLastReactiveExtensionsJSON-Schemaoptimizeremrfindupttyless compilereventDispatcherjQuerycorscolorinstallconcurrencyhasOwnPropertysqsdataview__proto__telephonestylesterminalstructuredClonereact-testing-librarycsslimittypescriptcss variablesharedchromedotenveventspipeduplextyped arraysetPrototypeOfclispecmkdirjavascriptremoveecmascriptclass-validatorconcatbeanstalkjoi$.extendzodnegativeObject.valuesargparsecode pointspicomatchregular expressionsregular expressionminimalobjectmimecollection.es6connectinternalcensorspeedeast-asian-widthECMAScript 6assertstoArrayfilereadablestreampackagetoolkitcompile lessrgbYAMLvpcvisualajvbrowserslistECMAScript 2016arraysUint8ClampedArrayiteratordomnodejsECMAScript 3weakmapmulti-packageextrapreserve-symlinkspreprocessorschemebindtypesafei18npromisees2017oncelastrecursivedefineprivate dataisConcatSpreadableiterateString.prototype.trimObject.assign
2.1.15

4 days ago

2.1.14

5 days ago

2.1.12

7 days ago

2.1.13

6 days ago

1.1.12

8 days ago

1.1.11

9 days ago

1.1.10

10 days ago

1.1.9

11 days ago

1.1.8

12 days ago

1.1.7

13 days ago

1.1.6

14 days ago

1.0.6

15 days ago

1.0.5

16 days ago

1.0.4

17 days ago

1.0.2

19 days ago

1.0.3

18 days ago

1.0.1

20 days ago

1.0.0

20 days ago