Skip to content

Commit

Permalink
style: add recommended mocha rules
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Nov 4, 2024
1 parent 35c8837 commit e6a43dc
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 44 deletions.
13 changes: 11 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
{
"root": true,
"extends": [ "@tpluscode" ],
"extends": [
"@tpluscode",
"plugin:mocha/recommended"
],
"plugins": [
"mocha"
],
"parserOptions": {
"project": "./tsconfig.json"
},
"env": {
"mocha": true
},
"rules": {
"@typescript-eslint/indent": ["error", 2, { "SwitchCase": 1, "ignoredNodes": ["PropertyDefinition"] }]
"@typescript-eslint/indent": ["error", 2, { "SwitchCase": 1, "ignoredNodes": ["PropertyDefinition"] }],
"mocha/no-setup-in-describe": "warn",
"mocha/no-sibling-hooks": "warn",
"mocha/max-top-level-suites": "off"
},
"overrides": [{
"files": ["*.test.ts"],
Expand Down
2 changes: 2 additions & 0 deletions apis/core/test/domain/csv-source/replace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('domain/csv-sources/replace', () => {

describe('when source is successfully parsed', () => {
let csvSourceUpdate: GraphPointer

beforeEach(async () => {
// given
csvSource = clownface({ dataset: $rdf.dataset() })
Expand Down Expand Up @@ -176,6 +177,7 @@ describe('domain/csv-sources/replace', () => {

describe('when source has different column order', () => {
let csvSourceUpdate: GraphPointer

beforeEach(async () => {
// given
csvSource = clownface({ dataset: $rdf.dataset() })
Expand Down
6 changes: 3 additions & 3 deletions apis/core/test/domain/csv/parse.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from 'chai'
import { parse } from '../../../lib/domain/csv'

describe('domain/csv/parse', () => {
it('trims headers', async () => {
describe('domain/csv/parse', function () {
it('trims headers', async function () {
// given
const input = '" station_id ","\tpollutant_id\t","aggregation_id\t","\tlimitvalue","year"'

Expand All @@ -14,7 +14,7 @@ describe('domain/csv/parse', () => {
expect(header).to.contain.ordered.members(['station_id', 'pollutant_id', 'aggregation_id', 'limitvalue', 'year'])
})

it('parses header', async () => {
it('parses header', async function () {
// given
const input = '"station_id","pollutant_id","aggregation_id","limitvalue","year"'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const { parsingClient } = mdClients

const ns = namespace('https://ld.admin.ch/cube/dimension/')

describe('@cube-creator/shared-dimensions-api/lib/shared-dimension/queries @SPARQL', () => {
describe('deleteDynamicTerms', () => {
describe('@cube-creator/shared-dimensions-api/lib/shared-dimension/queries @SPARQL', function () {
describe('deleteDynamicTerms', function () {
beforeEach(insertTestDimensions)

it('deletes dynamic property from terms', async () => {
it('deletes dynamic property from terms', async function () {
// when
await deleteDynamicTerms({
dimension: ns.technologies,
Expand All @@ -28,7 +28,7 @@ describe('@cube-creator/shared-dimensions-api/lib/shared-dimension/queries @SPAR
).to.eventually.be.false
})

it('does nothing when there are no deleted dimensions', async () => {
it('does nothing when there are no deleted dimensions', async function () {
// when
await deleteDynamicTerms({
dimension: ns.technologies,
Expand Down
1 change: 1 addition & 0 deletions apis/shared-dimensions/test/lib/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ graph ${ex('different-graph')} {
describe('shared-dimensions/lib/loader @SPARQL', () => {
const req = {} as any
let loader: ResourceLoader

before(async () => {
loader = new Loader({
graph,
Expand Down
54 changes: 28 additions & 26 deletions apis/shared-dimensions/test/store/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ const graph = $rdf.namedNode('https://lindas.admin.ch/cube/dimension')
const ns = namespace('https://ld.admin.ch/cube/dimension/')
const { parsingClient } = mdClients

describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', function () {
let store: SharedDimensionsStore

describe('exists', () => {
describe('exists', function () {
before(prepareStore)

it('returns true when a resource with given type exists in graph', async () => {
it('returns true when a resource with given type exists in graph', async function () {
// given
const id = $rdf.namedNode('https://ld.admin.ch/cube/dimension/technologies')

Expand All @@ -34,7 +34,7 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
await expect(exists).to.eventually.be.true
})

it('returns false when a resource with given type exists in a different graph', async () => {
it('returns false when a resource with given type exists in a different graph', async function () {
// given
const id = $rdf.namedNode('https://ld.admin.ch/cube/dimension/technologies')
await INSERT.DATA`
Expand All @@ -49,7 +49,7 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
await expect(exists).to.eventually.be.true
})

it('returns false when a resource exists in graph but not with the type', async () => {
it('returns false when a resource exists in graph but not with the type', async function () {
// given
const id = $rdf.namedNode('https://ld.admin.ch/cube/dimension/technologies')

Expand All @@ -59,7 +59,7 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
await expect(exists).to.eventually.be.false
})

it('returns false when a resource does no exist', async () => {
it('returns false when a resource does no exist', async function () {
// given
const id = $rdf.namedNode('https://ld.admin.ch/cube/dimension/foobar')

Expand All @@ -70,24 +70,25 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
})
})

describe('load', () => {
describe('load', function () {
beforeEach(prepareStore)
before(async () => {

before(async function () {
await INSERT.DATA`
GRAPH ${ex.otherGraph} {
${ns['technologies/sparql']} a ${ex.Something}
}
`.execute(parsingClient.query)
})

context('existing dimension', () => {
context('existing dimension', function () {
let dimension: GraphPointer

before(async () => {
before(async function () {
dimension = await store.load(ns.technologies)
})

it('loads base properties', () => {
it('loads base properties', function () {
expect(dimension).to.matchShape({
property: [{
path: rdf.type,
Expand All @@ -106,7 +107,7 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
})
})

it('loads dynamic properties', () => {
it('loads dynamic properties', function () {
const langStringProperty: Initializer<NodeShape> = {
property: [{
path: md.dynamicPropertyType,
Expand Down Expand Up @@ -177,14 +178,14 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
})
})

context('term with dynamic properties', () => {
context('term with dynamic properties', function () {
let dimensionTerm: GraphPointer

beforeEach(async () => {
beforeEach(async function () {
dimensionTerm = await store.load(ns['technologies/sparql'])
})

it('does not load data from other graphs', async () => {
it('does not load data from other graphs', async function () {
expect(dimensionTerm).not.to.matchShape({
property: {
path: rdf.type,
Expand All @@ -193,7 +194,7 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
})
})

it('gets loaded with common properties', () => {
it('gets loaded with common properties', function () {
expect(dimensionTerm).to.matchShape({
property: [{
path: schema.validFrom,
Expand All @@ -214,7 +215,7 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
})
})

it('gets loaded with dynamic property values', () => {
it('gets loaded with dynamic property values', function () {
expect(dimensionTerm).to.matchShape({
property: [{
path: rdfs.comment,
Expand All @@ -231,17 +232,18 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
})
})

describe('delete', () => {
describe('delete', function () {
beforeEach(prepareStore)
beforeEach(async () => {

beforeEach(async function () {
await INSERT.DATA`
GRAPH ${ex.otherGraph} {
${ns['technologies/sparql']} a ${ex.Something}
}
`.execute(parsingClient.query)
})

it('does not delete data from other graphs', async () => {
it('does not delete data from other graphs', async function () {
// given
const term = ns['technologies/sparql']

Expand All @@ -252,7 +254,7 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
await expect(ASK`${term} ?p ?o`.FROM(ex.otherGraph).execute(parsingClient.query)).to.eventually.be.true
})

it('deletes dimension term with dynamic properties', async () => {
it('deletes dimension term with dynamic properties', async function () {
// given
const term = ns['technologies/sparql']

Expand All @@ -263,7 +265,7 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
await expect(ASK`${term} ?p ?o`.FROM(graph).execute(parsingClient.query)).to.eventually.be.false
})

it('deletes dimension deep', async () => {
it('deletes dimension deep', async function () {
// given
const term = ns.technologies

Expand All @@ -275,10 +277,10 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
})
})

describe('save', () => {
describe('save', function () {
before(prepareStore)

it('inserts new resource', async () => {
it('inserts new resource', async function () {
// given
const term = namedNode(ns['technologies/owl'])
.addOut(rdf.type, [md.SharedDimensionTerm, hydra.Resource, schema.DefinedTerm])
Expand All @@ -300,7 +302,7 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
`.execute(parsingClient.query)).to.eventually.be.true
})

it('updates existing resource', async () => {
it('updates existing resource', async function () {
// given
const term = namedNode(ns['technologies/rdf'])
.addOut(rdf.type, [md.SharedDimensionTerm, hydra.Resource, schema.DefinedTerm])
Expand All @@ -325,7 +327,7 @@ describe('@cube-creator/shared-dimensions-api/lib/store/index @SPARQL', () => {
`.execute(parsingClient.query)).to.eventually.be.false
})

it('updates dynamic properties', async () => {
it('updates dynamic properties', async function () {
// given
const term = namedNode(ns['technologies/sparql'])
.addOut(rdf.type, [md.SharedDimensionTerm, hydra.Resource, schema.DefinedTerm])
Expand Down
8 changes: 8 additions & 0 deletions cli/test/lib/commands/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ describe('@cube-creator/cli/lib/commands/publish', function () {

describe('publishing published', () => {
before(resetData)

before(function makeCubePublished() {
return WITH(job, DELETE`
${job} ${schema.creativeWorkStatus} ?status
Expand All @@ -160,10 +161,13 @@ describe('@cube-creator/cli/lib/commands/publish', function () {
${job} ${schema.creativeWorkStatus} ?status
`).execute(ccClients.parsingClient.query)
})

before(runJob)

it('removes hydra terms', removesHydraTerms)

it('removes original values of mapped dimensions', removesMappingsOriginalValues)

it('adds qudt:hasUnit', duplicatesQudtUnit)

it('does not publish a cube with trailing slash', async () => {
Expand Down Expand Up @@ -214,11 +218,15 @@ describe('@cube-creator/cli/lib/commands/publish', function () {

describe('publishing draft', () => {
before(resetData)

before(runJob)

it('removes hydra terms', removesHydraTerms)

it('adds qudt:hasUnit', duplicatesQudtUnit)

it('removes original values of mapped dimensions', removesMappingsOriginalValues)

it('adds software versions', addsSoftwareVersions)

it('does not remove previously published triples', () => {
Expand Down
1 change: 1 addition & 0 deletions cli/test/lib/commands/unlist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('@cube-creator/cli/lib/commands/unlist', function () {
}

before(resetData)

before(runJob)

it('"deprecates" previous cubes', async function () {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"eslint-config-standard": "^17.0.0",
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-vue": "^9.8.0",
Expand Down
Loading

0 comments on commit e6a43dc

Please sign in to comment.