Skip to content

Commit

Permalink
MR to cut 0.0.5 release (#12)
Browse files Browse the repository at this point in the history
* initial adding jest

* fixing readme

* fixing readme

* ignoring testFiles folder for jest

* added tests for single export

* hex color tests

* working on check package json tests

* check package tests

* reset

* created package path

* setting the default

* test

* Revert "test"

This reverts commit ccb4aea.

* added tests for run

* creating demo github actions

* running build

* trying to run on every branch

* changed build name

* created failing test

* removing failed test

* trying to add status badge

* changed name

* added release status

* creating separate develop and release builds

* trying to publish on release build

* trying to run develop against all branches other than release

* added logic and unit test for requiring a git commit

* attempting to add coverage report

* trying this

* maybe this

* fixing command

* ts upgrade

* converting unit tests to ts

* working on tests

* npm i

* injecting dependecies for run

* fixing unit tests

* switching toffeenut.js to ts

* update git ignore

* deleting bin

* added feature branch build

* config git

* 0.1.1-next.0

* Revert "0.1.1-next.0"

This reverts commit b2a3a5e.

* Revert "Merge pull request #10 from TheBlindSquirrel/tsUpgrade"

This reverts commit 36b4bd3, reversing
changes made to 7320360.

* Add test to check how many times plugin is used (#11)

* initial working on plugin test

* moving test files to own folder

* created utils script

* moving hex color to utils

* updated readme

* updated readme

* switching single export to util

* initial work on creating plugin only called once test

* ignoring all directories called node_modules

* working on testing for plugins

* basic plugin test working. generating error message

* bug fix for custom plugin array

* added tests for plugins

* added the process file function

* more unit tests
  • Loading branch information
swernimo authored Aug 22, 2023
1 parent 1539fdc commit 020b80d
Show file tree
Hide file tree
Showing 34 changed files with 7,761 additions and 114 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

name: develop

on:
push:
branches:
- '*'
- '!release'

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Build
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
26 changes: 26 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: PR

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Build
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
- name: Comment with Test Coverage
uses: dkershner6/jest-coverage-commenter-action@v1
with:
github_token: "${{ secrets.GITHUB_TOKEN }}"
test_command: "npx jest --coverage"
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

name: release

on:
push:
branches: [ "release" ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Toffeenut

![Toffeenut Develop Status](https://github.com/TheBlindSquirrel/toffeenut/actions/workflows/develop.yml/badge.svg?branch=develop)
![Toffeenut Release Status](https://github.com/TheBlindSquirrel/toffeenut/actions/workflows/release.yml/badge.svg?branch=release)
## Design Psychology
Toffeenut is intended to be a library of fitness functions. It is not intended to be framework, like Jasmine, that allows you create your tests. Toffeenut instead contains a set of predefined tests that you run against your code base. Each test can be enabled or disabled to suite your preferences and the coding standards of your team. Depending on how many tests are have enabled and the size of your code base, it is not recommended to run Toffeenut on every check-in. Instead the recommendation is to run the suite as part of your MR/PR process.

Expand Down Expand Up @@ -40,8 +41,13 @@ enabled | true | If the test should be run | false
**since 0.0.2**
Config Name | Default Value | Description | Required
:---------: | :-----------: | :---------: | :--:
allowGithub | true | If true any packages installed directly from a git server will be allowed | false
allowGithub | true | If true any packages installed directly from a git server will be allowed. If false any git links will be marked as invalid and the test will fail. | false

**since 0.0.4**
Config Name | Default Value | Description | Required
:---------: | :-----------: | :---------: | :--:
requireGitCommit | false | This test will only run if allowGithub flag is also true. If true all packages installed from git must be pinned to a specific commit. | false
packagePath | ./package.json | The location of the package.json file to test. | true


### **Single Export**
Expand All @@ -56,9 +62,15 @@ rootPath | '' | The root folder to search through for all ts files | true


### **Plugin Only Called Once**
**since TDB**
**0.0.5**

This test will search through all ts files under the supplied root folder making sure that each plugin is only found in a single file.

This test will search through all ts/js files under the supplied root folder looking for files that call the supplied plugins.
Config Name | Default Value | Description | Required
:---------: | :-----------: | :---------: | :--:
rootPath | '' | The top level directory that contains all the ts files to check | true
enabled | true | If the test should be run | false
pluginsArray | [] | Array of plugin names to look for, in addiiton to the official Capacitor plugins. This [list](./scripts/pluginList.js) contains all the plugins that Toffeenut will check by default. | false

### **File Referenced Outside Folder**
**since TDB**
Expand Down Expand Up @@ -113,3 +125,14 @@ This test scans the code base for strings of the minimum length that are duplica
**since TDB**

This test is to prevent the style tag from being used in any html/htm file.


### **Treat Errors as Warnings**
**since TDB**

This is a global setting that if true the build will not fail due to failing toffeenut tests.

### **Duplicate Name**
**since TDB**

Checks if there are multiple files with the same name in different folders.
26 changes: 17 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,34 @@ const checkPackageJson = require('./scripts/checkPackageJson');
const run = require('./scripts/run');
const singleExport = require('./scripts/singleExport');
const hexColors = require('./scripts/hexColors');
const plugins = require('./scripts/plugins');

// run();
// const errorMsg = checkPackageJson({
// run.go()
// const errorMsg = checkPackageJson.run({
// "enabled": false,
// "allowGithub": true,
// "requireGitCommit": false
// "requireGitCommit": false,
// "packagePath": "./testFiles/package.json"
// });
const errorMsg = singleExport({
'enabled': true,
'rootPath': './testFiles/singleExport'
});
// const errorMsg = hexColors( {
// const errorMsg = singleExport.run({
// 'enabled': true,
// 'rootPath': './testFiles/singleExport'
// });
// const errorMsg = hexColors.run( {
// "enabled": true,
// "colorsFilePath": "./testFiles/hexColors/colorFile.scss",
// "checkHTML": true,
// "checkForRGBA": false,
// "checkForRGBA": true,
// "ignoreFiles": ["./testFiles/hexColors/ignoreThisFolder", "./testFiles/hexColors/ignoreThisFile.scss"],
// "rootPath": "./testFiles/hexColors"
// });

const errorMsg = plugins.run({
rootPath: './testfiles/plugins',
enabled: true,
pluginsArray: ['customPlugin/plugin']
});

errorMsg.forEach(msg => {
console.error(msg.red);
});
Expand Down
196 changes: 196 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
/*
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/

module.exports = {
// All imported modules in your tests should be mocked automatically
// automock: false,

// Stop running tests after `n` failures
// bail: 0,

// The directory where Jest should store its cached dependency information
// cacheDirectory: "/private/var/folders/wg/3krtrfrj4xl_n2rsm7mvys_00000gn/T/jest_dx",

// Automatically clear mock calls, instances, contexts and results before every test
clearMocks: true,

// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: false,

// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,

// The directory where Jest should output its coverage files
// coverageDirectory: undefined,

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,

// A path to a custom dependency extractor
// dependencyExtractor: undefined,

// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,

// The default configuration for fake timers
// fakeTimers: {
// "enableGlobally": false
// },

// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],

// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,

// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,

// A set of global variables that need to be available in all test environments
// globals: {},

// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",

// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],

// An array of file extensions your modules use
// moduleFileExtensions: [
// "js",
// "mjs",
// "cjs",
// "jsx",
// "ts",
// "tsx",
// "json",
// "node"
// ],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
// moduleNameMapper: {},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],

// Activates notifications for test results
// notify: false,

// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
// preset: undefined,

// Run tests from one or more projects
// projects: undefined,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,

// Automatically reset mock state before every test
// resetMocks: false,

// Reset the module registry before running each individual test
// resetModules: false,

// A path to a custom resolver
// resolver: undefined,

// Automatically restore mock state and implementation before every test
// restoreMocks: false,

// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,

// A list of paths to directories that Jest should use to search for files in
// roots: [
// "<rootDir>"
// ],

// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],

// The test environment that will be used for testing
// testEnvironment: "jest-environment-node",

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},

// Adds a location field to test results
// testLocationInResults: false,

// The glob patterns Jest uses to detect test files
testMatch: [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)"
],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
testPathIgnorePatterns: [
"/node_modules/",
"/testFiles"
],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],

// This option allows the use of a custom results processor
// testResultsProcessor: undefined,

// This option allows use of a custom test runner
// testRunner: "jest-circus/runner",

// A map from regular expressions to paths to transformers
// transform: undefined,

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "/node_modules/",
// "\\.pnp\\.[^\\/]+$"
// ],

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,

// Indicates whether each individual test should be reported during the run
// verbose: undefined,

// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],

// Whether to use watchman for file crawling
// watchman: true,
};
2 changes: 1 addition & 1 deletion lib/toffeenut.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (argv._){
init();
break;
case 'run':
run();
run.go();
break;
}
}
3 changes: 2 additions & 1 deletion models/ICheckPackageJsonConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface ICheckPackageJsonConfig {
enabled: boolean
allowGithub: boolean
requireGitCommit: boolean
requireGitCommit: boolean,
packagePath: string
}
Loading

0 comments on commit 020b80d

Please sign in to comment.